@estjs/signals 0.0.15-beta.9 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { isFunction, isObject, warn, error, isPlainObject, hasChanged, isArray, isSet, isMap, isWeakMap, isWeakSet, isStringNumber, hasOwn } from '@estjs/shared';
1
+ import { isFunction, isObject, warn, error, isPlainObject, hasChanged, isArray, isSet, isMap, isWeakMap, isWeakSet, hasOwn, isStringNumber } from '@estjs/shared';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defProps = Object.defineProperties;
@@ -27,58 +27,62 @@ var TriggerOpTypes = {
27
27
  DELETE: "DELETE",
28
28
  CLEAR: "CLEAR"
29
29
  };
30
- var SIGNAL_KEY = /* @__PURE__ */ Symbol("Signal_Key" );
31
30
  var ARRAY_KEY = /* @__PURE__ */ Symbol("Array_Key" );
32
31
  var COLLECTION_KEY = /* @__PURE__ */ Symbol("Collection_Key" );
33
32
  var WEAK_COLLECTION_KEY = /* @__PURE__ */ Symbol("WeakCollection_Key" );
33
+ var ITERATE_KEY = /* @__PURE__ */ Symbol("Iterate_Key" );
34
34
  var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array_Iterate_Key" );
35
35
 
36
36
  // src/propagation.ts
37
+ function enqueueEffect(effect2) {
38
+ var _a5;
39
+ (_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
40
+ }
37
41
  function propagate(link) {
38
42
  let next = link.nextSubLink;
39
43
  let stack;
40
44
  top: do {
41
45
  const sub = link.subNode;
42
- const queueBit = sub.flag & 64 /* QUEUED */;
43
46
  const watcherBit = sub.flag & 2 /* WATCHING */;
44
- let flags = sub.flag & -65 /* QUEUED */;
47
+ let flags = sub.flag;
45
48
  if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */ | 8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
46
- sub.flag = queueBit | watcherBit | flags | 32 /* PENDING */;
47
- } else if (flags & (16 /* DIRTY */ | 32 /* PENDING */)) ; else if (!(flags & (8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
49
+ sub.flag = flags | 32 /* PENDING */;
50
+ if (watcherBit) {
51
+ enqueueEffect(sub);
52
+ }
53
+ } else if (!(flags & (8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
48
54
  flags = 0 /* NONE */;
49
- sub.flag = queueBit | watcherBit;
50
55
  } else if (!(flags & 4 /* RECURSED_CHECK */)) {
51
- sub.flag = queueBit | watcherBit | (flags & -9 /* RECURSED */ | 32 /* PENDING */);
56
+ sub.flag = flags & -9 /* RECURSED */ | 32 /* PENDING */;
52
57
  } else if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */)) && isValidLink(link, sub)) {
53
- sub.flag = queueBit | watcherBit | (flags | 8 /* RECURSED */ | 32 /* PENDING */);
58
+ sub.flag = flags | (8 /* RECURSED */ | 32 /* PENDING */);
59
+ if (watcherBit) {
60
+ enqueueEffect(sub);
61
+ }
54
62
  flags &= 1 /* MUTABLE */;
55
63
  } else {
56
64
  flags = 0 /* NONE */;
57
- sub.flag = queueBit | watcherBit;
58
- }
59
- if (sub.flag & 2 /* WATCHING */) {
60
- enqueueEffect(sub);
61
65
  }
62
66
  if (flags & 1 /* MUTABLE */) {
63
67
  const subSubs = sub.subLink;
64
- if (subSubs) {
65
- const nextSub = (link = subSubs).nextSubLink;
66
- if (nextSub) {
68
+ if (subSubs !== void 0) {
69
+ const nextSub = subSubs.nextSubLink;
70
+ if (nextSub !== void 0) {
67
71
  stack = { value: next, prev: stack };
68
72
  next = nextSub;
69
73
  }
74
+ link = subSubs;
70
75
  continue;
71
76
  }
72
77
  }
73
- if (next) {
74
- link = next;
78
+ if ((link = next) !== void 0) {
75
79
  next = link.nextSubLink;
76
80
  continue;
77
81
  }
78
- while (stack) {
82
+ while (stack !== void 0) {
79
83
  link = stack.value;
80
84
  stack = stack.prev;
81
- if (link) {
85
+ if (link !== void 0) {
82
86
  next = link.nextSubLink;
83
87
  continue top;
84
88
  }
@@ -89,27 +93,16 @@ function propagate(link) {
89
93
  function shallowPropagate(link) {
90
94
  while (link) {
91
95
  const sub = link.subNode;
92
- const queueBit = sub.flag & 64 /* QUEUED */;
93
- const flags = sub.flag & -65 /* QUEUED */;
94
- if (!(flags & 16 /* DIRTY */) && flags & (1 /* MUTABLE */ | 32 /* PENDING */)) {
95
- const newFlags = queueBit | flags & -33 /* PENDING */ | 16 /* DIRTY */;
96
- sub.flag = newFlags;
97
- if (newFlags & 2 /* WATCHING */) {
96
+ const flags = sub.flag;
97
+ if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
98
+ sub.flag = flags | 16 /* DIRTY */;
99
+ if ((flags & (2 /* WATCHING */ | 4 /* RECURSED_CHECK */)) === 2 /* WATCHING */) {
98
100
  enqueueEffect(sub);
99
101
  }
100
- if (flags & 1 /* MUTABLE */ && sub.subLink) {
101
- shallowPropagate(sub.subLink);
102
- }
103
102
  }
104
103
  link = link.nextSubLink;
105
104
  }
106
105
  }
107
- function enqueueEffect(effect2) {
108
- if (!effect2.active) {
109
- return;
110
- }
111
- effect2.notify();
112
- }
113
106
 
114
107
  // src/link.ts
115
108
  var currentLinkVersion = 0;
@@ -213,67 +206,76 @@ function unlinkReactiveNode(linkNode, subNode = linkNode.subNode) {
213
206
  }
214
207
  }
215
208
  }
216
- linkNode.depNode = void 0;
217
- linkNode.subNode = void 0;
218
- linkNode.prevSubLink = void 0;
219
- linkNode.nextSubLink = void 0;
220
- linkNode.prevDepLink = void 0;
221
- linkNode.nextDepLink = void 0;
222
209
  return nextDep;
223
210
  }
224
211
  function checkDirty(link, sub) {
225
- const stack = [{ link, owner: sub }];
226
- const pendingNodes = [];
227
- while (stack.length > 0) {
228
- const frame = stack.pop();
229
- let current = frame.link;
230
- const owner = frame.owner;
231
- while (current) {
232
- const dep = current.depNode;
212
+ let stack;
213
+ let checkDepth = 0;
214
+ let dirty = false;
215
+ top: do {
216
+ let currentDirty = false;
217
+ if (sub.flag & 16 /* DIRTY */) {
218
+ currentDirty = true;
219
+ } else {
220
+ const dep = link.depNode;
233
221
  const depFlags = dep.flag;
234
- if (owner.flag & 16 /* DIRTY */) {
235
- return true;
236
- }
237
222
  if ((depFlags & (1 /* MUTABLE */ | 16 /* DIRTY */)) === (1 /* MUTABLE */ | 16 /* DIRTY */)) {
238
223
  const subs = dep.subLink;
239
224
  if (subs && subs.nextSubLink) {
240
225
  shallowPropagate2(subs);
241
226
  }
242
- for (const node of pendingNodes) {
243
- if (node.flag & 32 /* PENDING */) {
244
- node.flag = node.flag & -33 /* PENDING */ | 16 /* DIRTY */;
245
- }
246
- }
247
- return true;
248
- }
249
- if ((depFlags & (1 /* MUTABLE */ | 32 /* PENDING */)) === (1 /* MUTABLE */ | 32 /* PENDING */)) {
227
+ currentDirty = true;
228
+ } else if ((depFlags & (1 /* MUTABLE */ | 32 /* PENDING */)) === (1 /* MUTABLE */ | 32 /* PENDING */)) {
250
229
  if (dep.depLink) {
251
- pendingNodes.push(dep);
252
- stack.push({ link: dep.depLink, owner: dep });
230
+ stack = { link, prev: stack };
231
+ link = dep.depLink;
232
+ sub = dep;
233
+ ++checkDepth;
234
+ continue top;
253
235
  } else {
254
236
  dep.flag &= -33 /* PENDING */;
255
237
  }
256
238
  } else if (depFlags & 32 /* PENDING */) {
257
239
  dep.flag &= -33 /* PENDING */;
258
240
  }
259
- current = current.nextDepLink;
260
241
  }
261
- }
262
- for (const node of pendingNodes) {
263
- node.flag &= -33 /* PENDING */;
264
- }
265
- if (sub.flag & 32 /* PENDING */) {
266
- sub.flag &= -33 /* PENDING */;
267
- }
268
- return false;
242
+ if (!currentDirty && link.nextDepLink !== void 0) {
243
+ link = link.nextDepLink;
244
+ continue top;
245
+ }
246
+ dirty = currentDirty;
247
+ while (checkDepth--) {
248
+ link = stack.link;
249
+ stack = stack.prev;
250
+ sub = link.subNode;
251
+ const checkedDep = link.depNode;
252
+ if (dirty) {
253
+ checkedDep.flag = checkedDep.flag & -33 /* PENDING */ | 16 /* DIRTY */;
254
+ } else {
255
+ checkedDep.flag &= -33 /* PENDING */;
256
+ }
257
+ if (checkedDep.flag & 16 /* DIRTY */) {
258
+ dirty = true;
259
+ }
260
+ if (!dirty && link.nextDepLink !== void 0) {
261
+ link = link.nextDepLink;
262
+ continue top;
263
+ }
264
+ }
265
+ if (dirty) {
266
+ sub.flag = sub.flag & -33 /* PENDING */ | 16 /* DIRTY */;
267
+ } else {
268
+ sub.flag &= -33 /* PENDING */;
269
+ }
270
+ return dirty;
271
+ } while (true);
269
272
  }
270
273
  function shallowPropagate2(link) {
271
274
  while (link) {
272
275
  const sub = link.subNode;
273
- const queueBit = sub.flag & 64 /* QUEUED */;
274
- const flags = sub.flag & -65 /* QUEUED */;
276
+ const flags = sub.flag;
275
277
  if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
276
- sub.flag = queueBit | flags | 16 /* DIRTY */;
278
+ sub.flag = flags | 16 /* DIRTY */;
277
279
  }
278
280
  link = link.nextSubLink;
279
281
  }
@@ -320,6 +322,23 @@ function isValidLink(checkLink, sub) {
320
322
  return false;
321
323
  }
322
324
  var targetMap = /* @__PURE__ */ new WeakMap();
325
+ var triggerVersion = 0;
326
+ function collectTriggeredEffects(dep, effects, version) {
327
+ if (!dep) {
328
+ return;
329
+ }
330
+ dep.forEach((effect2) => {
331
+ if (effect2.flag & 2 /* WATCHING */ && !effect2._active) {
332
+ dep.delete(effect2);
333
+ return;
334
+ }
335
+ if (effect2._triggerVersion === version) {
336
+ return;
337
+ }
338
+ effect2._triggerVersion = version;
339
+ effects.push(effect2);
340
+ });
341
+ }
323
342
  function track(target, key) {
324
343
  if (!activeSub || isUntracking) {
325
344
  return;
@@ -334,50 +353,39 @@ function track(target, key) {
334
353
  dep = /* @__PURE__ */ new Set();
335
354
  depsMap.set(key, dep);
336
355
  }
337
- if (!dep.has(activeSub)) {
338
- dep.add(activeSub);
339
- if (isFunction(activeSub.onTrack)) {
340
- activeSub.onTrack({
341
- effect: activeSub,
342
- target,
343
- type: "get",
344
- key
345
- });
346
- }
356
+ const sizeBefore = dep.size ;
357
+ dep.add(activeSub);
358
+ if (dep.size !== sizeBefore && isFunction(activeSub.onTrack)) {
359
+ activeSub.onTrack({
360
+ effect: activeSub,
361
+ target,
362
+ type: "get",
363
+ key
364
+ });
347
365
  }
348
366
  }
349
367
  function trigger(target, type, key, newValue) {
368
+ var _a5;
350
369
  const depsMap = targetMap.get(target);
351
370
  if (!depsMap) {
352
371
  return;
353
372
  }
354
- const effects = /* @__PURE__ */ new Set();
373
+ const effects = [];
374
+ const version = ++triggerVersion;
355
375
  if (key !== void 0) {
356
376
  if (Array.isArray(key)) {
357
- key.forEach((k) => {
358
- const dep = depsMap.get(k);
359
- if (dep) {
360
- dep.forEach((effect2) => effects.add(effect2));
361
- }
362
- });
363
- } else {
364
- const dep = depsMap.get(key);
365
- if (dep) {
366
- dep.forEach((effect2) => effects.add(effect2));
377
+ for (const element of key) {
378
+ collectTriggeredEffects(depsMap.get(element), effects, version);
367
379
  }
380
+ } else {
381
+ collectTriggeredEffects(depsMap.get(key), effects, version);
368
382
  }
369
383
  }
370
384
  if (type === "ADD" || type === "DELETE" || type === "CLEAR") {
371
- const ITERATE_KEY = /* @__PURE__ */ Symbol("iterate");
372
- const ARRAY_ITERATE_KEY2 = /* @__PURE__ */ Symbol("arrayIterate");
373
- const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY2 : ITERATE_KEY;
374
- const iterationDep = depsMap.get(iterationKey);
375
- if (iterationDep) {
376
- iterationDep.forEach((effect2) => effects.add(effect2));
377
- }
385
+ const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY : ITERATE_KEY;
386
+ collectTriggeredEffects(depsMap.get(iterationKey), effects, version);
378
387
  }
379
- effects.forEach((effect2) => {
380
- var _a5;
388
+ for (const effect2 of effects) {
381
389
  if (isFunction(effect2.onTrigger)) {
382
390
  effect2.onTrigger({
383
391
  effect: effect2,
@@ -395,7 +403,7 @@ function trigger(target, type, key, newValue) {
395
403
  propagate(effect2.subLink);
396
404
  }
397
405
  }
398
- });
406
+ }
399
407
  }
400
408
  var reactiveCaches = /* @__PURE__ */ new WeakMap();
401
409
  function toRaw(value) {
@@ -443,8 +451,7 @@ function createArrayInstrumentations() {
443
451
  instrumentations[key] = function(...args) {
444
452
  const arr = toRaw(this);
445
453
  const res = Array.prototype[key].apply(arr, args);
446
- trigger(arr, TriggerOpTypes.SET, ARRAY_KEY);
447
- trigger(arr, TriggerOpTypes.SET, ARRAY_ITERATE_KEY);
454
+ trigger(arr, TriggerOpTypes.SET, [ARRAY_KEY, ARRAY_ITERATE_KEY]);
448
455
  return res;
449
456
  };
450
457
  }
@@ -847,6 +854,8 @@ var objectHandlers = (shallow) => ({
847
854
  return result;
848
855
  }
849
856
  });
857
+ var shallowObjectHandlers = objectHandlers(true);
858
+ var deepObjectHandlers = objectHandlers(false);
850
859
  function reactiveImpl(target, shallow = false) {
851
860
  if (!isObject(target)) {
852
861
  return target;
@@ -866,7 +875,7 @@ function reactiveImpl(target, shallow = false) {
866
875
  } else if (isWeakMap(target) || isWeakSet(target)) {
867
876
  handler = weakCollectionHandlers;
868
877
  } else {
869
- handler = objectHandlers(shallow);
878
+ handler = shallow ? shallowObjectHandlers : deepObjectHandlers;
870
879
  }
871
880
  const proxy = new Proxy(target, handler);
872
881
  reactiveCaches.set(target, proxy);
@@ -902,7 +911,6 @@ var toReactive = (value) => isObject(value) ? reactive(value) : value;
902
911
  var _a;
903
912
  _a = "_IS_SIGNAL" /* IS_SIGNAL */;
904
913
  var SignalImpl = class {
905
- // Mark as Signal
906
914
  /**
907
915
  * Create a new Signal with the given initial value.
908
916
  *
@@ -912,15 +920,20 @@ var SignalImpl = class {
912
920
  constructor(value, shallow = false) {
913
921
  this.flag = 1 /* MUTABLE */;
914
922
  // Mark whether it's shallow reactive
915
- // @ts-ignore
923
+ // @ts-ignore: used internally by isSignal typeguard
916
924
  this[_a] = true;
917
- this._rawValue = value;
918
- if (shallow) {
919
- this._value = isObject(value) ? shallowReactive(value) : value;
925
+ const unwrapped = toRaw(value);
926
+ this._rawValue = unwrapped;
927
+ this["_IS_SHALLOW" /* IS_SHALLOW */] = shallow;
928
+ if (!isObject(unwrapped)) {
929
+ this._value = unwrapped;
920
930
  } else {
921
- this._value = isObject(value) ? reactive(value) : value;
931
+ if (isReactive(value)) {
932
+ this._value = value;
933
+ } else {
934
+ this._value = shallow ? shallowReactive(unwrapped) : reactive(unwrapped);
935
+ }
922
936
  }
923
- this["_IS_SHALLOW" /* IS_SHALLOW */] = shallow;
924
937
  }
925
938
  // dep getter, returns itself for dependency collection
926
939
  get dep() {
@@ -941,37 +954,37 @@ var SignalImpl = class {
941
954
  return this._value;
942
955
  }
943
956
  // value setter, triggers update when value changes
944
- set value(value) {
945
- if (isSignal(value)) {
957
+ set value(newValue) {
958
+ if (isSignal(newValue)) {
946
959
  {
947
960
  warn(
948
961
  "Setting a signal value to another signal is not recommended. The value will be unwrapped automatically."
949
962
  );
950
963
  }
951
- value = value.peek();
964
+ newValue = newValue.peek();
952
965
  }
953
- value = toRaw(value);
954
- if (!hasChanged(this._rawValue, value)) {
966
+ const originalValue = newValue;
967
+ const rawValue = toRaw(newValue);
968
+ if (!hasChanged(this._rawValue, rawValue)) {
955
969
  return;
956
970
  }
957
- if (!("_oldValue" in this)) {
958
- this._oldValue = this._rawValue;
959
- }
960
- const flags = this.flag;
961
- this.flag = flags | 16 /* DIRTY */;
962
- this._rawValue = value;
963
- const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
964
- if (shallow) {
965
- this._value = isObject(value) ? shallowReactive(value) : value;
971
+ this._oldValue = this._rawValue;
972
+ this._rawValue = rawValue;
973
+ this.flag |= 16 /* DIRTY */;
974
+ if (!isObject(rawValue)) {
975
+ this._value = rawValue;
976
+ } else if (isReactive(originalValue)) {
977
+ this._value = originalValue;
966
978
  } else {
967
- this._value = isObject(value) ? reactive(value) : value;
979
+ const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
980
+ this._value = shallow ? shallowReactive(rawValue) : reactive(rawValue);
968
981
  }
969
982
  const subs = this.subLink;
970
983
  if (subs) {
971
984
  propagate(subs);
972
985
  }
973
986
  }
974
- // Check if the value should be update
987
+ // Check if the value should be updated
975
988
  shouldUpdate() {
976
989
  this.flag &= -17 /* DIRTY */;
977
990
  if (!("_oldValue" in this)) {
@@ -1029,19 +1042,7 @@ var activePreFlushCbs = /* @__PURE__ */ new Set();
1029
1042
  var p = Promise.resolve();
1030
1043
  var isFlushPending = false;
1031
1044
  function nextTick(fn) {
1032
- if (fn) {
1033
- return new Promise((resolve, reject) => {
1034
- queueMicrotask(() => {
1035
- try {
1036
- fn();
1037
- resolve();
1038
- } catch (error5) {
1039
- reject(error5);
1040
- }
1041
- });
1042
- });
1043
- }
1044
- return p;
1045
+ return fn ? p.then(fn) : p;
1045
1046
  }
1046
1047
  function queueJob(job) {
1047
1048
  queue.add(job);
@@ -1061,9 +1062,7 @@ function flushJobs() {
1061
1062
  isFlushPending = false;
1062
1063
  flushPreFlushCbs();
1063
1064
  while (queue.size > 0) {
1064
- const jobs = Array.from(queue);
1065
- queue.clear();
1066
- for (const job of jobs) {
1065
+ for (const job of queue) {
1067
1066
  try {
1068
1067
  job();
1069
1068
  } catch (_error) {
@@ -1072,6 +1071,7 @@ function flushJobs() {
1072
1071
  }
1073
1072
  }
1074
1073
  }
1074
+ queue.clear();
1075
1075
  }
1076
1076
  }
1077
1077
  function flushPreFlushCbs() {
@@ -1147,16 +1147,22 @@ var EffectImpl = class {
1147
1147
  */
1148
1148
  constructor(fn, options) {
1149
1149
  this.flag = 2 /* WATCHING */ | 16 /* DIRTY */;
1150
- // @ts-ignore
1150
+ // @ts-ignore: used internally by isEffect typeguard
1151
1151
  this[_a2] = true;
1152
- // State management
1152
+ // State management
1153
1153
  this._active = true;
1154
+ var _a5;
1154
1155
  this.fn = fn;
1155
1156
  if (options) {
1156
- this.scheduler = options.flush || options.scheduler;
1157
- this.onStop = options.onStop;
1158
- this.onTrack = options.onTrack;
1159
- this.onTrigger = options.onTrigger;
1157
+ const scheduler = (_a5 = options.scheduler) != null ? _a5 : options.flush;
1158
+ if (scheduler) {
1159
+ this._flushScheduler = isFunction(scheduler) ? () => scheduler(this) : createScheduler(() => this.run(), scheduler);
1160
+ }
1161
+ if (options.onStop) this.onStop = options.onStop;
1162
+ {
1163
+ if (options.onTrack) this.onTrack = options.onTrack;
1164
+ if (options.onTrigger) this.onTrigger = options.onTrigger;
1165
+ }
1160
1166
  }
1161
1167
  }
1162
1168
  /**
@@ -1166,9 +1172,8 @@ var EffectImpl = class {
1166
1172
  return this._active;
1167
1173
  }
1168
1174
  /**
1169
- * Check if the Effect is dirty (needs re-execution)
1170
-
1171
- */
1175
+ * Check if the Effect is dirty (needs re-execution)
1176
+ */
1172
1177
  get dirty() {
1173
1178
  const flags = this.flag;
1174
1179
  if (flags & 16 /* DIRTY */) {
@@ -1263,7 +1268,7 @@ var EffectImpl = class {
1263
1268
  return this.fn();
1264
1269
  }
1265
1270
  const flags = this.flag;
1266
- this.flag = flags & -17 /* DIRTY */ | 1024 /* STOP */;
1271
+ this.flag = flags & -49 | 512 /* RUNNING */;
1267
1272
  const prevSub = startTracking(this);
1268
1273
  try {
1269
1274
  return this.fn();
@@ -1271,7 +1276,7 @@ var EffectImpl = class {
1271
1276
  this.flag |= 16 /* DIRTY */;
1272
1277
  throw error5;
1273
1278
  } finally {
1274
- this.flag &= -1025 /* STOP */;
1279
+ this.flag &= -513 /* RUNNING */;
1275
1280
  endTracking(this, prevSub);
1276
1281
  }
1277
1282
  }
@@ -1291,25 +1296,21 @@ var EffectImpl = class {
1291
1296
  * Decides whether to execute immediately or defer based on scheduling strategy.
1292
1297
  */
1293
1298
  notify() {
1299
+ var _a5;
1294
1300
  const flags = this.flag;
1295
- if (!this._active || flags & (256 /* PAUSED */ | 1024 /* STOP */ | 16 /* DIRTY */)) {
1301
+ if (!this._active || flags & (256 /* PAUSED */ | 512 /* RUNNING */ | 16 /* DIRTY */)) {
1296
1302
  return;
1297
1303
  }
1298
1304
  this.flag = flags | 16 /* DIRTY */;
1299
- if (this.onTrigger) {
1305
+ if (this == null ? void 0 : this.onTrigger) {
1300
1306
  this.onTrigger({
1301
1307
  effect: this,
1302
1308
  target: {},
1303
1309
  type: "set"
1304
1310
  });
1305
1311
  }
1306
- if (this.scheduler) {
1307
- if (isFunction(this.scheduler)) {
1308
- this.scheduler(this);
1309
- } else {
1310
- const schedulerFn = createScheduler(() => this.run(), this.scheduler);
1311
- schedulerFn();
1312
- }
1312
+ if (this._flushScheduler) {
1313
+ (_a5 = this._flushScheduler) == null ? void 0 : _a5.call(this);
1313
1314
  } else if (isBatching()) {
1314
1315
  queueJob(this.getJob());
1315
1316
  } else {
@@ -1343,6 +1344,7 @@ var EffectImpl = class {
1343
1344
  sub = unlinkReactiveNode(sub);
1344
1345
  }
1345
1346
  this._job = void 0;
1347
+ this._flushScheduler = void 0;
1346
1348
  this.depLinkTail = void 0;
1347
1349
  this.subLinkTail = void 0;
1348
1350
  {
@@ -1357,7 +1359,7 @@ var EffectImpl = class {
1357
1359
  );
1358
1360
  }
1359
1361
  }
1360
- if (this.onStop) {
1362
+ if (this == null ? void 0 : this.onStop) {
1361
1363
  this.onStop();
1362
1364
  }
1363
1365
  }
@@ -1409,7 +1411,7 @@ var ComputedImpl = class {
1409
1411
  */
1410
1412
  constructor(getter, setter, onTrack, onTrigger) {
1411
1413
  this.flag = 1 /* MUTABLE */ | 16 /* DIRTY */;
1412
- //@ts-ignore
1414
+ // @ts-ignore: used internally by isComputed typeguard
1413
1415
  this[_a3] = true;
1414
1416
  // Cache
1415
1417
  // Use symbol sentinel to distinguish "no value" from undefined/null values
@@ -1470,7 +1472,7 @@ var ComputedImpl = class {
1470
1472
  /**
1471
1473
  * Recompute the value
1472
1474
  *
1473
- * computation logic:
1475
+ * computation logic:
1474
1476
  * 1. Start tracking dependencies
1475
1477
  * 2. Execute getter function
1476
1478
  * 3. Check if value changed using optimized comparison
@@ -1509,7 +1511,7 @@ var ComputedImpl = class {
1509
1511
  } catch (_error) {
1510
1512
  const clearMask = -49;
1511
1513
  this.flag &= clearMask;
1512
- this.flag |= 16 /* DIRTY */;
1514
+ this._value = NO_VALUE;
1513
1515
  {
1514
1516
  error(
1515
1517
  "[Computed] Error occurred while computing value.\nThe computed will retry on next access.\nCommon causes:\n - Accessing undefined properties\n - Circular dependencies\n - Exceptions in getter function\nCheck your getter function for errors.",
@@ -1633,39 +1635,23 @@ function createOptionsStore(options) {
1633
1635
  if (getters) {
1634
1636
  for (const key in getters) {
1635
1637
  const getter = getters[key];
1636
- if (getter) {
1637
- let accessCount = 0;
1638
- let lastWarnTime = 0;
1639
- Object.defineProperty(store, key, {
1640
- get() {
1641
- {
1642
- accessCount++;
1643
- const now = Date.now();
1644
- if (accessCount > 100 && now - lastWarnTime > 1e3) {
1645
- warn(
1646
- `Getter '${key}' has been accessed ${accessCount} times. Consider caching the result if the value is used frequently. Note: Getters are computed properties that recalculate on every access.`
1647
- );
1648
- lastWarnTime = now;
1649
- accessCount = 0;
1650
- }
1651
- }
1652
- return computed(() => getter.call(store, reactiveState)).value;
1653
- },
1654
- enumerable: true,
1655
- configurable: true
1656
- });
1657
- }
1638
+ if (!getter) continue;
1639
+ Object.defineProperty(store, key, {
1640
+ get: () => computed(() => getter.call(store, reactiveState)).value,
1641
+ enumerable: true,
1642
+ configurable: true
1643
+ });
1658
1644
  }
1659
1645
  }
1660
1646
  if (actions) {
1661
1647
  for (const key in actions) {
1662
1648
  const action = actions[key];
1663
1649
  if (action) {
1664
- store[key] = (...args) => {
1650
+ Reflect.set(store, key, (...args) => {
1665
1651
  const result = action.apply(reactiveState, args);
1666
1652
  actionCallbacks.forEach((callback) => callback(reactiveState));
1667
1653
  return result;
1668
- };
1654
+ });
1669
1655
  }
1670
1656
  }
1671
1657
  }
@@ -1706,15 +1692,15 @@ function createStore(storeDefinition) {
1706
1692
  }
1707
1693
  return () => {
1708
1694
  let options;
1709
- if (typeof storeDefinition === "function") {
1695
+ if (isFunction(storeDefinition)) {
1710
1696
  options = createClassStore(storeDefinition);
1711
1697
  } else {
1712
1698
  options = storeDefinition;
1713
1699
  }
1714
1700
  const store = createOptionsStore(options);
1715
- if (typeof storeDefinition === "function") {
1716
- Object.keys(options.actions || {}).forEach((key) => {
1717
- store[key] = options.actions[key].bind(store);
1701
+ if (isFunction(storeDefinition) && options.actions) {
1702
+ Object.keys(options.actions).forEach((key) => {
1703
+ Reflect.set(store, key, options.actions[key].bind(store));
1718
1704
  });
1719
1705
  }
1720
1706
  return store;
@@ -1729,26 +1715,30 @@ var RefImpl = class extends (_b = SignalImpl, _a4 = "_IS_REF" /* IS_REF */, _b)
1729
1715
  */
1730
1716
  constructor(value) {
1731
1717
  super(value, true);
1732
- // @ts-ignore
1718
+ // @ts-ignore: used internally by isRef typeguard
1733
1719
  this[_a4] = true;
1734
1720
  }
1735
1721
  get value() {
1736
- track(this, SIGNAL_KEY);
1722
+ const sub = activeSub;
1723
+ if (sub) {
1724
+ linkReactiveNode(this, sub);
1725
+ }
1737
1726
  return this._value;
1738
1727
  }
1739
1728
  set value(newValue) {
1740
1729
  if (isSignal(newValue)) {
1741
- newValue = newValue.value;
1730
+ newValue = newValue.peek();
1742
1731
  }
1743
1732
  if (isRef(newValue)) {
1744
1733
  newValue = newValue.value;
1745
1734
  }
1746
1735
  if (hasChanged(this._value, newValue)) {
1736
+ this._rawValue = newValue;
1747
1737
  this._value = newValue;
1738
+ this.flag |= 16 /* DIRTY */;
1748
1739
  if (this.subLink) {
1749
- shallowPropagate2(this.subLink);
1740
+ propagate(this.subLink);
1750
1741
  }
1751
- trigger(this, "SET", SIGNAL_KEY);
1752
1742
  }
1753
1743
  }
1754
1744
  };