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