@estjs/signals 0.0.15-beta.8 → 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,10 +1,5 @@
1
- import { isFunction, isObject, warn, error, isPlainObject, info, 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
- /**
4
- * @estjs/signals v0.0.15-beta.8
5
- * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
6
- * @license MIT
7
- **/
8
3
  var __defProp = Object.defineProperty;
9
4
  var __defProps = Object.defineProperties;
10
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -32,58 +27,62 @@ var TriggerOpTypes = {
32
27
  DELETE: "DELETE",
33
28
  CLEAR: "CLEAR"
34
29
  };
35
- var SIGNAL_KEY = Symbol("Signal_Key" );
36
- var ARRAY_KEY = Symbol("Array_Key" );
37
- var COLLECTION_KEY = Symbol("Collection_Key" );
38
- var WEAK_COLLECTION_KEY = Symbol("WeakCollection_Key" );
39
- var ARRAY_ITERATE_KEY = Symbol("Array_Iterate_Key" );
30
+ var ARRAY_KEY = /* @__PURE__ */ Symbol("Array_Key" );
31
+ var COLLECTION_KEY = /* @__PURE__ */ Symbol("Collection_Key" );
32
+ var WEAK_COLLECTION_KEY = /* @__PURE__ */ Symbol("WeakCollection_Key" );
33
+ var ITERATE_KEY = /* @__PURE__ */ Symbol("Iterate_Key" );
34
+ var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array_Iterate_Key" );
40
35
 
41
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
+ }
42
41
  function propagate(link) {
43
42
  let next = link.nextSubLink;
44
43
  let stack;
45
44
  top: do {
46
45
  const sub = link.subNode;
47
- const queueBit = sub.flag & 64 /* QUEUED */;
48
46
  const watcherBit = sub.flag & 2 /* WATCHING */;
49
- let flags = sub.flag & -65 /* QUEUED */;
47
+ let flags = sub.flag;
50
48
  if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */ | 8 /* RECURSED */ | 4 /* RECURSED_CHECK */))) {
51
- sub.flag = queueBit | watcherBit | flags | 32 /* PENDING */;
52
- } 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 */))) {
53
54
  flags = 0 /* NONE */;
54
- sub.flag = queueBit | watcherBit;
55
55
  } else if (!(flags & 4 /* RECURSED_CHECK */)) {
56
- sub.flag = queueBit | watcherBit | (flags & -9 /* RECURSED */ | 32 /* PENDING */);
56
+ sub.flag = flags & -9 /* RECURSED */ | 32 /* PENDING */;
57
57
  } else if (!(flags & (16 /* DIRTY */ | 32 /* PENDING */)) && isValidLink(link, sub)) {
58
- sub.flag = queueBit | watcherBit | (flags | 8 /* RECURSED */ | 32 /* PENDING */);
58
+ sub.flag = flags | (8 /* RECURSED */ | 32 /* PENDING */);
59
+ if (watcherBit) {
60
+ enqueueEffect(sub);
61
+ }
59
62
  flags &= 1 /* MUTABLE */;
60
63
  } else {
61
64
  flags = 0 /* NONE */;
62
- sub.flag = queueBit | watcherBit;
63
- }
64
- if (sub.flag & 2 /* WATCHING */) {
65
- enqueueEffect(sub);
66
65
  }
67
66
  if (flags & 1 /* MUTABLE */) {
68
67
  const subSubs = sub.subLink;
69
- if (subSubs) {
70
- const nextSub = (link = subSubs).nextSubLink;
71
- if (nextSub) {
68
+ if (subSubs !== void 0) {
69
+ const nextSub = subSubs.nextSubLink;
70
+ if (nextSub !== void 0) {
72
71
  stack = { value: next, prev: stack };
73
72
  next = nextSub;
74
73
  }
74
+ link = subSubs;
75
75
  continue;
76
76
  }
77
77
  }
78
- if (next) {
79
- link = next;
78
+ if ((link = next) !== void 0) {
80
79
  next = link.nextSubLink;
81
80
  continue;
82
81
  }
83
- while (stack) {
82
+ while (stack !== void 0) {
84
83
  link = stack.value;
85
84
  stack = stack.prev;
86
- if (link) {
85
+ if (link !== void 0) {
87
86
  next = link.nextSubLink;
88
87
  continue top;
89
88
  }
@@ -94,27 +93,16 @@ function propagate(link) {
94
93
  function shallowPropagate(link) {
95
94
  while (link) {
96
95
  const sub = link.subNode;
97
- const queueBit = sub.flag & 64 /* QUEUED */;
98
- const flags = sub.flag & -65 /* QUEUED */;
99
- if (!(flags & 16 /* DIRTY */) && flags & (1 /* MUTABLE */ | 32 /* PENDING */)) {
100
- const newFlags = queueBit | flags & -33 /* PENDING */ | 16 /* DIRTY */;
101
- sub.flag = newFlags;
102
- 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 */) {
103
100
  enqueueEffect(sub);
104
101
  }
105
- if (flags & 1 /* MUTABLE */ && sub.subLink) {
106
- shallowPropagate(sub.subLink);
107
- }
108
102
  }
109
103
  link = link.nextSubLink;
110
104
  }
111
105
  }
112
- function enqueueEffect(effect2) {
113
- if (!effect2.active) {
114
- return;
115
- }
116
- effect2.notify();
117
- }
118
106
 
119
107
  // src/link.ts
120
108
  var currentLinkVersion = 0;
@@ -218,67 +206,76 @@ function unlinkReactiveNode(linkNode, subNode = linkNode.subNode) {
218
206
  }
219
207
  }
220
208
  }
221
- linkNode.depNode = void 0;
222
- linkNode.subNode = void 0;
223
- linkNode.prevSubLink = void 0;
224
- linkNode.nextSubLink = void 0;
225
- linkNode.prevDepLink = void 0;
226
- linkNode.nextDepLink = void 0;
227
209
  return nextDep;
228
210
  }
229
211
  function checkDirty(link, sub) {
230
- const stack = [{ link, owner: sub }];
231
- const pendingNodes = [];
232
- while (stack.length > 0) {
233
- const frame = stack.pop();
234
- let current = frame.link;
235
- const owner = frame.owner;
236
- while (current) {
237
- 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;
238
221
  const depFlags = dep.flag;
239
- if (owner.flag & 16 /* DIRTY */) {
240
- return true;
241
- }
242
222
  if ((depFlags & (1 /* MUTABLE */ | 16 /* DIRTY */)) === (1 /* MUTABLE */ | 16 /* DIRTY */)) {
243
223
  const subs = dep.subLink;
244
224
  if (subs && subs.nextSubLink) {
245
225
  shallowPropagate2(subs);
246
226
  }
247
- for (const node of pendingNodes) {
248
- if (node.flag & 32 /* PENDING */) {
249
- node.flag = node.flag & -33 /* PENDING */ | 16 /* DIRTY */;
250
- }
251
- }
252
- return true;
253
- }
254
- 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 */)) {
255
229
  if (dep.depLink) {
256
- pendingNodes.push(dep);
257
- stack.push({ link: dep.depLink, owner: dep });
230
+ stack = { link, prev: stack };
231
+ link = dep.depLink;
232
+ sub = dep;
233
+ ++checkDepth;
234
+ continue top;
258
235
  } else {
259
236
  dep.flag &= -33 /* PENDING */;
260
237
  }
261
238
  } else if (depFlags & 32 /* PENDING */) {
262
239
  dep.flag &= -33 /* PENDING */;
263
240
  }
264
- current = current.nextDepLink;
265
241
  }
266
- }
267
- for (const node of pendingNodes) {
268
- node.flag &= -33 /* PENDING */;
269
- }
270
- if (sub.flag & 32 /* PENDING */) {
271
- sub.flag &= -33 /* PENDING */;
272
- }
273
- 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);
274
272
  }
275
273
  function shallowPropagate2(link) {
276
274
  while (link) {
277
275
  const sub = link.subNode;
278
- const queueBit = sub.flag & 64 /* QUEUED */;
279
- const flags = sub.flag & -65 /* QUEUED */;
276
+ const flags = sub.flag;
280
277
  if ((flags & (32 /* PENDING */ | 16 /* DIRTY */)) === 32 /* PENDING */) {
281
- sub.flag = queueBit | flags | 16 /* DIRTY */;
278
+ sub.flag = flags | 16 /* DIRTY */;
282
279
  }
283
280
  link = link.nextSubLink;
284
281
  }
@@ -325,6 +322,23 @@ function isValidLink(checkLink, sub) {
325
322
  return false;
326
323
  }
327
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
+ }
328
342
  function track(target, key) {
329
343
  if (!activeSub || isUntracking) {
330
344
  return;
@@ -339,50 +353,39 @@ function track(target, key) {
339
353
  dep = /* @__PURE__ */ new Set();
340
354
  depsMap.set(key, dep);
341
355
  }
342
- if (!dep.has(activeSub)) {
343
- dep.add(activeSub);
344
- if (isFunction(activeSub.onTrack)) {
345
- activeSub.onTrack({
346
- effect: activeSub,
347
- target,
348
- type: "get",
349
- key
350
- });
351
- }
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
+ });
352
365
  }
353
366
  }
354
367
  function trigger(target, type, key, newValue) {
368
+ var _a5;
355
369
  const depsMap = targetMap.get(target);
356
370
  if (!depsMap) {
357
371
  return;
358
372
  }
359
- const effects = /* @__PURE__ */ new Set();
373
+ const effects = [];
374
+ const version = ++triggerVersion;
360
375
  if (key !== void 0) {
361
376
  if (Array.isArray(key)) {
362
- key.forEach((k) => {
363
- const dep = depsMap.get(k);
364
- if (dep) {
365
- dep.forEach((effect2) => effects.add(effect2));
366
- }
367
- });
368
- } else {
369
- const dep = depsMap.get(key);
370
- if (dep) {
371
- dep.forEach((effect2) => effects.add(effect2));
377
+ for (const element of key) {
378
+ collectTriggeredEffects(depsMap.get(element), effects, version);
372
379
  }
380
+ } else {
381
+ collectTriggeredEffects(depsMap.get(key), effects, version);
373
382
  }
374
383
  }
375
384
  if (type === "ADD" || type === "DELETE" || type === "CLEAR") {
376
- const ITERATE_KEY2 = Symbol("iterate");
377
- const ARRAY_ITERATE_KEY2 = Symbol("arrayIterate");
378
- const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY2 : ITERATE_KEY2;
379
- const iterationDep = depsMap.get(iterationKey);
380
- if (iterationDep) {
381
- iterationDep.forEach((effect2) => effects.add(effect2));
382
- }
385
+ const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY : ITERATE_KEY;
386
+ collectTriggeredEffects(depsMap.get(iterationKey), effects, version);
383
387
  }
384
- effects.forEach((effect2) => {
385
- var _a5;
388
+ for (const effect2 of effects) {
386
389
  if (isFunction(effect2.onTrigger)) {
387
390
  effect2.onTrigger({
388
391
  effect: effect2,
@@ -400,7 +403,7 @@ function trigger(target, type, key, newValue) {
400
403
  propagate(effect2.subLink);
401
404
  }
402
405
  }
403
- });
406
+ }
404
407
  }
405
408
  var reactiveCaches = /* @__PURE__ */ new WeakMap();
406
409
  function toRaw(value) {
@@ -448,8 +451,7 @@ function createArrayInstrumentations() {
448
451
  instrumentations[key] = function(...args) {
449
452
  const arr = toRaw(this);
450
453
  const res = Array.prototype[key].apply(arr, args);
451
- trigger(arr, TriggerOpTypes.SET, ARRAY_KEY);
452
- trigger(arr, TriggerOpTypes.SET, ARRAY_ITERATE_KEY);
454
+ trigger(arr, TriggerOpTypes.SET, [ARRAY_KEY, ARRAY_ITERATE_KEY]);
453
455
  return res;
454
456
  };
455
457
  }
@@ -852,6 +854,8 @@ var objectHandlers = (shallow) => ({
852
854
  return result;
853
855
  }
854
856
  });
857
+ var shallowObjectHandlers = objectHandlers(true);
858
+ var deepObjectHandlers = objectHandlers(false);
855
859
  function reactiveImpl(target, shallow = false) {
856
860
  if (!isObject(target)) {
857
861
  return target;
@@ -871,7 +875,7 @@ function reactiveImpl(target, shallow = false) {
871
875
  } else if (isWeakMap(target) || isWeakSet(target)) {
872
876
  handler = weakCollectionHandlers;
873
877
  } else {
874
- handler = objectHandlers(shallow);
878
+ handler = shallow ? shallowObjectHandlers : deepObjectHandlers;
875
879
  }
876
880
  const proxy = new Proxy(target, handler);
877
881
  reactiveCaches.set(target, proxy);
@@ -882,44 +886,18 @@ function isReactive(target) {
882
886
  }
883
887
  function reactive(target) {
884
888
  if (isReactive(target)) {
885
- {
886
- warn(
887
- "[Reactive] Target is already reactive. Returning existing reactive proxy to avoid double wrapping."
888
- );
889
- }
890
889
  return target;
891
890
  }
892
891
  if (isSignal(target)) {
893
- {
894
- warn(
895
- "[Reactive] Creating a reactive proxy from a signal is not recommended. Use the signal directly or access its value property."
896
- );
897
- }
898
892
  return target;
899
893
  }
900
894
  return reactiveImpl(target);
901
895
  }
902
896
  function shallowReactive(target) {
903
897
  if (isReactive(target)) {
904
- {
905
- if (isShallow(target)) {
906
- warn(
907
- "[ShallowReactive] Target is already a shallow reactive proxy. Returning existing proxy to avoid double wrapping."
908
- );
909
- } else {
910
- warn(
911
- "[ShallowReactive] Target is already a deep reactive proxy. Cannot convert deep reactive to shallow reactive. Returning existing proxy."
912
- );
913
- }
914
- }
915
898
  return target;
916
899
  }
917
900
  if (isSignal(target)) {
918
- {
919
- warn(
920
- "[ShallowReactive] Creating a reactive proxy from a signal is not recommended. Use the signal directly or access its value property."
921
- );
922
- }
923
901
  return target;
924
902
  }
925
903
  return reactiveImpl(target, true);
@@ -933,7 +911,6 @@ var toReactive = (value) => isObject(value) ? reactive(value) : value;
933
911
  var _a;
934
912
  _a = "_IS_SIGNAL" /* IS_SIGNAL */;
935
913
  var SignalImpl = class {
936
- // Mark as Signal
937
914
  /**
938
915
  * Create a new Signal with the given initial value.
939
916
  *
@@ -943,15 +920,20 @@ var SignalImpl = class {
943
920
  constructor(value, shallow = false) {
944
921
  this.flag = 1 /* MUTABLE */;
945
922
  // Mark whether it's shallow reactive
946
- // @ts-ignore
923
+ // @ts-ignore: used internally by isSignal typeguard
947
924
  this[_a] = true;
948
- this._rawValue = value;
949
- if (shallow) {
950
- 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;
951
930
  } else {
952
- 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
+ }
953
936
  }
954
- this["_IS_SHALLOW" /* IS_SHALLOW */] = shallow;
955
937
  }
956
938
  // dep getter, returns itself for dependency collection
957
939
  get dep() {
@@ -972,37 +954,37 @@ var SignalImpl = class {
972
954
  return this._value;
973
955
  }
974
956
  // value setter, triggers update when value changes
975
- set value(value) {
976
- if (isSignal(value)) {
957
+ set value(newValue) {
958
+ if (isSignal(newValue)) {
977
959
  {
978
960
  warn(
979
961
  "Setting a signal value to another signal is not recommended. The value will be unwrapped automatically."
980
962
  );
981
963
  }
982
- value = value.peek();
964
+ newValue = newValue.peek();
983
965
  }
984
- value = toRaw(value);
985
- if (!hasChanged(this._rawValue, value)) {
966
+ const originalValue = newValue;
967
+ const rawValue = toRaw(newValue);
968
+ if (!hasChanged(this._rawValue, rawValue)) {
986
969
  return;
987
970
  }
988
- if (!("_oldValue" in this)) {
989
- this._oldValue = this._rawValue;
990
- }
991
- const flags = this.flag;
992
- this.flag = flags | 16 /* DIRTY */;
993
- this._rawValue = value;
994
- const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
995
- if (shallow) {
996
- 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;
997
978
  } else {
998
- this._value = isObject(value) ? reactive(value) : value;
979
+ const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
980
+ this._value = shallow ? shallowReactive(rawValue) : reactive(rawValue);
999
981
  }
1000
982
  const subs = this.subLink;
1001
983
  if (subs) {
1002
984
  propagate(subs);
1003
985
  }
1004
986
  }
1005
- // Check if the value should be update
987
+ // Check if the value should be updated
1006
988
  shouldUpdate() {
1007
989
  this.flag &= -17 /* DIRTY */;
1008
990
  if (!("_oldValue" in this)) {
@@ -1048,11 +1030,6 @@ function signal(value) {
1048
1030
  }
1049
1031
  function shallowSignal(value) {
1050
1032
  if (isSignal(value)) {
1051
- {
1052
- warn(
1053
- "Creating a shallow signal with another signal is not recommended. The value will be unwrapped."
1054
- );
1055
- }
1056
1033
  value = value.peek();
1057
1034
  }
1058
1035
  return new SignalImpl(value, true);
@@ -1065,19 +1042,7 @@ var activePreFlushCbs = /* @__PURE__ */ new Set();
1065
1042
  var p = Promise.resolve();
1066
1043
  var isFlushPending = false;
1067
1044
  function nextTick(fn) {
1068
- if (fn) {
1069
- return new Promise((resolve, reject) => {
1070
- queueMicrotask(() => {
1071
- try {
1072
- fn();
1073
- resolve();
1074
- } catch (error5) {
1075
- reject(error5);
1076
- }
1077
- });
1078
- });
1079
- }
1080
- return p;
1045
+ return fn ? p.then(fn) : p;
1081
1046
  }
1082
1047
  function queueJob(job) {
1083
1048
  queue.add(job);
@@ -1097,9 +1062,7 @@ function flushJobs() {
1097
1062
  isFlushPending = false;
1098
1063
  flushPreFlushCbs();
1099
1064
  while (queue.size > 0) {
1100
- const jobs = Array.from(queue);
1101
- queue.clear();
1102
- for (const job of jobs) {
1065
+ for (const job of queue) {
1103
1066
  try {
1104
1067
  job();
1105
1068
  } catch (_error) {
@@ -1108,6 +1071,7 @@ function flushJobs() {
1108
1071
  }
1109
1072
  }
1110
1073
  }
1074
+ queue.clear();
1111
1075
  }
1112
1076
  }
1113
1077
  function flushPreFlushCbs() {
@@ -1183,16 +1147,22 @@ var EffectImpl = class {
1183
1147
  */
1184
1148
  constructor(fn, options) {
1185
1149
  this.flag = 2 /* WATCHING */ | 16 /* DIRTY */;
1186
- // @ts-ignore
1150
+ // @ts-ignore: used internally by isEffect typeguard
1187
1151
  this[_a2] = true;
1188
- // ===== State management =====
1152
+ // State management
1189
1153
  this._active = true;
1154
+ var _a5;
1190
1155
  this.fn = fn;
1191
1156
  if (options) {
1192
- this.scheduler = options.flush || options.scheduler;
1193
- this.onStop = options.onStop;
1194
- this.onTrack = options.onTrack;
1195
- 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
+ }
1196
1166
  }
1197
1167
  }
1198
1168
  /**
@@ -1202,9 +1172,8 @@ var EffectImpl = class {
1202
1172
  return this._active;
1203
1173
  }
1204
1174
  /**
1205
- * Check if the Effect is dirty (needs re-execution)
1206
-
1207
- */
1175
+ * Check if the Effect is dirty (needs re-execution)
1176
+ */
1208
1177
  get dirty() {
1209
1178
  const flags = this.flag;
1210
1179
  if (flags & 16 /* DIRTY */) {
@@ -1299,7 +1268,7 @@ var EffectImpl = class {
1299
1268
  return this.fn();
1300
1269
  }
1301
1270
  const flags = this.flag;
1302
- this.flag = flags & -17 /* DIRTY */ | 1024 /* STOP */;
1271
+ this.flag = flags & -49 | 512 /* RUNNING */;
1303
1272
  const prevSub = startTracking(this);
1304
1273
  try {
1305
1274
  return this.fn();
@@ -1307,7 +1276,7 @@ var EffectImpl = class {
1307
1276
  this.flag |= 16 /* DIRTY */;
1308
1277
  throw error5;
1309
1278
  } finally {
1310
- this.flag &= -1025 /* STOP */;
1279
+ this.flag &= -513 /* RUNNING */;
1311
1280
  endTracking(this, prevSub);
1312
1281
  }
1313
1282
  }
@@ -1327,25 +1296,21 @@ var EffectImpl = class {
1327
1296
  * Decides whether to execute immediately or defer based on scheduling strategy.
1328
1297
  */
1329
1298
  notify() {
1299
+ var _a5;
1330
1300
  const flags = this.flag;
1331
- if (!this._active || flags & (256 /* PAUSED */ | 1024 /* STOP */ | 16 /* DIRTY */)) {
1301
+ if (!this._active || flags & (256 /* PAUSED */ | 512 /* RUNNING */ | 16 /* DIRTY */)) {
1332
1302
  return;
1333
1303
  }
1334
1304
  this.flag = flags | 16 /* DIRTY */;
1335
- if (this.onTrigger) {
1305
+ if (this == null ? void 0 : this.onTrigger) {
1336
1306
  this.onTrigger({
1337
1307
  effect: this,
1338
1308
  target: {},
1339
1309
  type: "set"
1340
1310
  });
1341
1311
  }
1342
- if (this.scheduler) {
1343
- if (isFunction(this.scheduler)) {
1344
- this.scheduler(this);
1345
- } else {
1346
- const schedulerFn = createScheduler(() => this.run(), this.scheduler);
1347
- schedulerFn();
1348
- }
1312
+ if (this._flushScheduler) {
1313
+ (_a5 = this._flushScheduler) == null ? void 0 : _a5.call(this);
1349
1314
  } else if (isBatching()) {
1350
1315
  queueJob(this.getJob());
1351
1316
  } else {
@@ -1379,6 +1344,7 @@ var EffectImpl = class {
1379
1344
  sub = unlinkReactiveNode(sub);
1380
1345
  }
1381
1346
  this._job = void 0;
1347
+ this._flushScheduler = void 0;
1382
1348
  this.depLinkTail = void 0;
1383
1349
  this.subLinkTail = void 0;
1384
1350
  {
@@ -1393,7 +1359,7 @@ var EffectImpl = class {
1393
1359
  );
1394
1360
  }
1395
1361
  }
1396
- if (this.onStop) {
1362
+ if (this == null ? void 0 : this.onStop) {
1397
1363
  this.onStop();
1398
1364
  }
1399
1365
  }
@@ -1431,7 +1397,7 @@ function memoEffect(fn, initialState, options) {
1431
1397
  };
1432
1398
  return effect(effectFn, options);
1433
1399
  }
1434
- var NO_VALUE = Symbol("computed-no-value");
1400
+ var NO_VALUE = /* @__PURE__ */ Symbol("computed-no-value");
1435
1401
  var _a3;
1436
1402
  _a3 = "_IS_COMPUTED" /* IS_COMPUTED */;
1437
1403
  var ComputedImpl = class {
@@ -1445,9 +1411,9 @@ var ComputedImpl = class {
1445
1411
  */
1446
1412
  constructor(getter, setter, onTrack, onTrigger) {
1447
1413
  this.flag = 1 /* MUTABLE */ | 16 /* DIRTY */;
1448
- //@ts-ignore
1414
+ // @ts-ignore: used internally by isComputed typeguard
1449
1415
  this[_a3] = true;
1450
- // ===== Cache =====
1416
+ // Cache
1451
1417
  // Use symbol sentinel to distinguish "no value" from undefined/null values
1452
1418
  this._value = NO_VALUE;
1453
1419
  this.getter = getter;
@@ -1506,7 +1472,7 @@ var ComputedImpl = class {
1506
1472
  /**
1507
1473
  * Recompute the value
1508
1474
  *
1509
- * computation logic:
1475
+ * computation logic:
1510
1476
  * 1. Start tracking dependencies
1511
1477
  * 2. Execute getter function
1512
1478
  * 3. Check if value changed using optimized comparison
@@ -1545,7 +1511,7 @@ var ComputedImpl = class {
1545
1511
  } catch (_error) {
1546
1512
  const clearMask = -49;
1547
1513
  this.flag &= clearMask;
1548
- this.flag |= 16 /* DIRTY */;
1514
+ this._value = NO_VALUE;
1549
1515
  {
1550
1516
  error(
1551
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.",
@@ -1669,39 +1635,23 @@ function createOptionsStore(options) {
1669
1635
  if (getters) {
1670
1636
  for (const key in getters) {
1671
1637
  const getter = getters[key];
1672
- if (getter) {
1673
- let accessCount = 0;
1674
- let lastWarnTime = 0;
1675
- Object.defineProperty(store, key, {
1676
- get() {
1677
- {
1678
- accessCount++;
1679
- const now = Date.now();
1680
- if (accessCount > 100 && now - lastWarnTime > 1e3) {
1681
- warn(
1682
- `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.`
1683
- );
1684
- lastWarnTime = now;
1685
- accessCount = 0;
1686
- }
1687
- }
1688
- return computed(() => getter.call(store, reactiveState)).value;
1689
- },
1690
- enumerable: true,
1691
- configurable: true
1692
- });
1693
- }
1638
+ if (!getter) continue;
1639
+ Object.defineProperty(store, key, {
1640
+ get: () => computed(() => getter.call(store, reactiveState)).value,
1641
+ enumerable: true,
1642
+ configurable: true
1643
+ });
1694
1644
  }
1695
1645
  }
1696
1646
  if (actions) {
1697
1647
  for (const key in actions) {
1698
1648
  const action = actions[key];
1699
1649
  if (action) {
1700
- store[key] = (...args) => {
1650
+ Reflect.set(store, key, (...args) => {
1701
1651
  const result = action.apply(reactiveState, args);
1702
1652
  actionCallbacks.forEach((callback) => callback(reactiveState));
1703
1653
  return result;
1704
- };
1654
+ });
1705
1655
  }
1706
1656
  }
1707
1657
  }
@@ -1742,15 +1692,15 @@ function createStore(storeDefinition) {
1742
1692
  }
1743
1693
  return () => {
1744
1694
  let options;
1745
- if (typeof storeDefinition === "function") {
1695
+ if (isFunction(storeDefinition)) {
1746
1696
  options = createClassStore(storeDefinition);
1747
1697
  } else {
1748
1698
  options = storeDefinition;
1749
1699
  }
1750
1700
  const store = createOptionsStore(options);
1751
- if (typeof storeDefinition === "function") {
1752
- Object.keys(options.actions || {}).forEach((key) => {
1753
- 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));
1754
1704
  });
1755
1705
  }
1756
1706
  return store;
@@ -1765,40 +1715,38 @@ var RefImpl = class extends (_b = SignalImpl, _a4 = "_IS_REF" /* IS_REF */, _b)
1765
1715
  */
1766
1716
  constructor(value) {
1767
1717
  super(value, true);
1768
- // @ts-ignore
1718
+ // @ts-ignore: used internally by isRef typeguard
1769
1719
  this[_a4] = true;
1770
1720
  }
1771
1721
  get value() {
1772
- track(this, SIGNAL_KEY);
1722
+ const sub = activeSub;
1723
+ if (sub) {
1724
+ linkReactiveNode(this, sub);
1725
+ }
1773
1726
  return this._value;
1774
1727
  }
1775
1728
  set value(newValue) {
1776
1729
  if (isSignal(newValue)) {
1777
- newValue = newValue.value;
1730
+ newValue = newValue.peek();
1778
1731
  }
1779
1732
  if (isRef(newValue)) {
1780
1733
  newValue = newValue.value;
1781
1734
  }
1782
1735
  if (hasChanged(this._value, newValue)) {
1736
+ this._rawValue = newValue;
1783
1737
  this._value = newValue;
1738
+ this.flag |= 16 /* DIRTY */;
1784
1739
  if (this.subLink) {
1785
- shallowPropagate2(this.subLink);
1740
+ propagate(this.subLink);
1786
1741
  }
1787
- trigger(this, "SET", SIGNAL_KEY);
1788
1742
  }
1789
1743
  }
1790
1744
  };
1791
1745
  function ref(value = void 0) {
1792
1746
  if (isRef(value)) {
1793
- {
1794
- info("Creating a ref with another ref is not recommended. The value will be unwrapped.");
1795
- }
1796
1747
  return value;
1797
1748
  }
1798
1749
  if (isSignal(value)) {
1799
- {
1800
- info("Creating a ref with a signal is not recommended. The value will be unwrapped.");
1801
- }
1802
1750
  return new RefImpl(value.peek());
1803
1751
  }
1804
1752
  return new RefImpl(value);