@but212/atom-effect 0.3.1 → 0.3.2

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.
package/dist/index.mjs CHANGED
@@ -28,7 +28,7 @@ const T = {
28
28
  MAX_SIZE: 1e3,
29
29
  /** Number of objects to pre-allocate for performance-critical paths */
30
30
  WARMUP_SIZE: 100
31
- }, U = {
31
+ }, A = {
32
32
  /** Maximum effect executions per second to detect infinite loops (Legacy/Fallback) */
33
33
  MAX_EXECUTIONS_PER_SECOND: 100,
34
34
  /** Threshold for cleaning up old execution timestamps */
@@ -48,7 +48,7 @@ const T = {
48
48
  MAX_DEPENDENCIES: 1e3,
49
49
  /** Enable infinite loop detection warnings */
50
50
  WARN_INFINITE_LOOP: !0
51
- }, N = 1073741823, w = typeof process < "u" && process.env && process.env.NODE_ENV !== "production";
51
+ }, D = 1073741823, M = typeof process < "u" && process.env && process.env.NODE_ENV !== "production";
52
52
  class d extends Error {
53
53
  /**
54
54
  * Creates a new AtomError
@@ -60,7 +60,7 @@ class d extends Error {
60
60
  super(e), this.name = "AtomError", this.cause = t, this.recoverable = s, this.timestamp = /* @__PURE__ */ new Date();
61
61
  }
62
62
  }
63
- class D extends d {
63
+ class I extends d {
64
64
  /**
65
65
  * Creates a new ComputedError
66
66
  * @param message - Error message
@@ -70,7 +70,7 @@ class D extends d {
70
70
  super(e, t, !0), this.name = "ComputedError";
71
71
  }
72
72
  }
73
- class S extends d {
73
+ class g extends d {
74
74
  /**
75
75
  * Creates a new EffectError
76
76
  * @param message - Error message
@@ -190,19 +190,19 @@ const a = {
190
190
  };
191
191
  let P = 0;
192
192
  function G() {
193
- return P = (P + 1 | 0) & N, P;
193
+ return P = (P + 1 | 0) & D, P;
194
194
  }
195
- let A = 0, v = 0, O = !1;
195
+ let U = 0, w = 0, O = !1;
196
196
  function q() {
197
- return O ? (w && console.warn(
197
+ return O ? (M && console.warn(
198
198
  "Warning: startFlush() called during flush - ignored to prevent infinite loop detection bypass"
199
- ), !1) : (O = !0, A = A + 1 & N, v = 0, !0);
199
+ ), !1) : (O = !0, U = U + 1 & D, w = 0, !0);
200
200
  }
201
201
  function z() {
202
202
  O = !1;
203
203
  }
204
204
  function H() {
205
- return O ? ++v : 0;
205
+ return O ? ++w : 0;
206
206
  }
207
207
  class J {
208
208
  constructor() {
@@ -385,20 +385,20 @@ class J {
385
385
  this.maxFlushIterations = e;
386
386
  }
387
387
  }
388
- const m = new J();
388
+ const N = new J();
389
389
  function ne(i) {
390
390
  if (typeof i != "function")
391
391
  throw new d("Batch callback must be a function");
392
- m.startBatch();
392
+ N.startBatch();
393
393
  try {
394
394
  return i();
395
395
  } catch (e) {
396
396
  throw new d("Error occurred during batch execution", e);
397
397
  } finally {
398
- m.endBatch();
398
+ N.endBatch();
399
399
  }
400
400
  }
401
- const y = {
401
+ const m = {
402
402
  /** @inheritdoc */
403
403
  current: null,
404
404
  /**
@@ -422,26 +422,26 @@ const y = {
422
422
  function re(i) {
423
423
  if (typeof i != "function")
424
424
  throw new d("Untracked callback must be a function");
425
- const e = y.current;
426
- y.current = null;
425
+ const e = m.current;
426
+ m.current = null;
427
427
  try {
428
428
  return i();
429
429
  } catch (t) {
430
430
  throw new d("Error occurred during untracked execution", t);
431
431
  } finally {
432
- y.current = e;
432
+ m.current = e;
433
433
  }
434
434
  }
435
- const L = /* @__PURE__ */ Symbol("debugName"), W = /* @__PURE__ */ Symbol("id"), M = /* @__PURE__ */ Symbol("type"), j = /* @__PURE__ */ Symbol("noDefaultValue");
435
+ const v = /* @__PURE__ */ Symbol("debugName"), W = /* @__PURE__ */ Symbol("id"), L = /* @__PURE__ */ Symbol("type"), V = /* @__PURE__ */ Symbol("noDefaultValue");
436
436
  function K(i) {
437
437
  return i !== null && typeof i == "object" && "dependencies" in i && Array.isArray(i.dependencies);
438
438
  }
439
- let V = 0;
439
+ let j = 0;
440
440
  function Y(i, e, t) {
441
441
  const s = i;
442
442
  if (s._visitedEpoch !== t) {
443
443
  if (s._visitedEpoch = t, i === e)
444
- throw new D("Indirect circular dependency detected");
444
+ throw new I("Indirect circular dependency detected");
445
445
  if (K(i)) {
446
446
  const n = i.dependencies;
447
447
  for (let r = 0; r < n.length; r++)
@@ -514,8 +514,8 @@ const b = {
514
514
  */
515
515
  checkCircular(i, e, t) {
516
516
  if (i === e)
517
- throw new D("Direct circular dependency detected");
518
- this.enabled && (V++, Y(i, e, V));
517
+ throw new I("Direct circular dependency detected");
518
+ this.enabled && (j++, Y(i, e, j));
519
519
  },
520
520
  /**
521
521
  * Attaches debug metadata to a reactive object.
@@ -541,7 +541,7 @@ const b = {
541
541
  if (!this.enabled)
542
542
  return;
543
543
  const s = i;
544
- s[L] = `${e}_${t}`, s[W] = t, s[M] = e;
544
+ s[v] = `${e}_${t}`, s[W] = t, s[L] = e;
545
545
  },
546
546
  /**
547
547
  * Retrieves the debug display name from a reactive object.
@@ -556,8 +556,8 @@ const b = {
556
556
  * ```
557
557
  */
558
558
  getDebugName(i) {
559
- if (i !== null && typeof i == "object" && L in i)
560
- return i[L];
559
+ if (i !== null && typeof i == "object" && v in i)
560
+ return i[v];
561
561
  },
562
562
  /**
563
563
  * Retrieves the debug type from a reactive object.
@@ -574,8 +574,8 @@ const b = {
574
574
  * ```
575
575
  */
576
576
  getDebugType(i) {
577
- if (i !== null && typeof i == "object" && M in i)
578
- return i[M];
577
+ if (i !== null && typeof i == "object" && L in i)
578
+ return i[L];
579
579
  }
580
580
  };
581
581
  let Z = 1;
@@ -721,7 +721,7 @@ class ee {
721
721
  * @param sync - Whether to notify subscribers synchronously
722
722
  */
723
723
  constructor(e, t) {
724
- this._isNotificationScheduled = !1, this.id = B() & N, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = e, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), b.attachDebugInfo(this, "atom", this.id);
724
+ this._isNotificationScheduled = !1, this.id = B() & D, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = e, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._sync = t, this._notifyTask = this._flushNotifications.bind(this), b.attachDebugInfo(this, "atom", this.id);
725
725
  }
726
726
  /**
727
727
  * Gets the current value and registers the atom as a dependency
@@ -734,7 +734,7 @@ class ee {
734
734
  * a computed or effect context.
735
735
  */
736
736
  get value() {
737
- const e = y.getCurrent();
737
+ const e = m.getCurrent();
738
738
  return e != null && this._track(e), this._value;
739
739
  }
740
740
  /**
@@ -750,7 +750,7 @@ class ee {
750
750
  set value(e) {
751
751
  if (Object.is(this._value, e)) return;
752
752
  const t = this._value;
753
- this.version = this.version + 1 & N;
753
+ this.version = this.version + 1 & D;
754
754
  const s = this.version;
755
755
  this._value = e, !(!this._functionSubscribers.hasSubscribers && !this._objectSubscribers.hasSubscribers) && this._notify(e, t, s);
756
756
  }
@@ -790,7 +790,7 @@ class ee {
790
790
  * but don't schedule a new task. The pending task will see the latest value.
791
791
  */
792
792
  _notify(e, t, s) {
793
- this._isNotificationScheduled || (this._pendingOldValue = t, this._isNotificationScheduled = !0), this._sync && !m.isBatching ? this._flushNotifications() : m.schedule(this._notifyTask);
793
+ this._isNotificationScheduled || (this._pendingOldValue = t, this._isNotificationScheduled = !0), this._sync && !N.isBatching ? this._flushNotifications() : N.schedule(this._notifyTask);
794
794
  }
795
795
  /**
796
796
  * Executes the pending notifications.
@@ -907,18 +907,12 @@ class $ {
907
907
  this.pool.length = 0, p && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
908
908
  }
909
909
  }
910
- const g = new $(), I = new $();
910
+ const S = new $(), y = new $();
911
911
  class Q {
912
912
  constructor(e, t = {}) {
913
913
  if (typeof e != "function")
914
- throw new D(a.COMPUTED_MUST_BE_FUNCTION);
915
- if (this.id = B() & N, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = void 0, this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : j, this._hasDefaultValue = this._defaultValue !== j, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._dependencies = f, this._unsubscribes = E, this._recomputeJob = () => {
916
- if (this._isDirty())
917
- try {
918
- this._recompute();
919
- } catch {
920
- }
921
- }, this._notifyJob = () => {
914
+ throw new I(a.COMPUTED_MUST_BE_FUNCTION);
915
+ if (this.id = B() & D, this.version = 0, this.flags = 0, this._lastSeenEpoch = -1, this._value = void 0, this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._promiseId = 0, this._equal = t.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in t ? t.defaultValue : V, this._hasDefaultValue = this._defaultValue !== V, this._onError = t.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribers = new x(), this._objectSubscribers = new x(), this._dependencies = f, this._unsubscribes = E, this._notifyJob = () => {
922
916
  this._functionSubscribers.forEachSafe(
923
917
  (s) => s(),
924
918
  (s) => console.error(s)
@@ -950,7 +944,7 @@ class Q {
950
944
  if (typeof e == "object" && e !== null && "execute" in e)
951
945
  return this._objectSubscribers.add(e);
952
946
  if (typeof e != "function")
953
- throw new D(a.COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION);
947
+ throw new I(a.COMPUTED_SUBSCRIBER_MUST_BE_FUNCTION);
954
948
  return this._functionSubscribers.add(e);
955
949
  }
956
950
  peek() {
@@ -980,9 +974,9 @@ class Q {
980
974
  const t = this._unsubscribes[e];
981
975
  t && t();
982
976
  }
983
- I.release(this._unsubscribes), this._unsubscribes = E;
977
+ y.release(this._unsubscribes), this._unsubscribes = E;
984
978
  }
985
- this._dependencies !== f && (g.release(this._dependencies), this._dependencies = f), this._functionSubscribers.clear(), this._objectSubscribers.clear(), this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
979
+ this._dependencies !== f && (S.release(this._dependencies), this._dependencies = f), this._functionSubscribers.clear(), this._objectSubscribers.clear(), this._stateFlags = h.DIRTY | h.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
986
980
  }
987
981
  // === PRIVATE: State Flag Operations (inlined for performance) ===
988
982
  _isDirty() {
@@ -1040,7 +1034,7 @@ class Q {
1040
1034
  if (!this._isDirty() && this._isResolved())
1041
1035
  return;
1042
1036
  this._setRecomputing(!0);
1043
- const e = this._dependencies, t = g.acquire(), s = G();
1037
+ const e = this._dependencies, t = S.acquire(), s = G();
1044
1038
  let n = 0;
1045
1039
  const r = (_) => {
1046
1040
  _._lastSeenEpoch !== s && (_._lastSeenEpoch = s, n < t.length ? t[n] = _ : t.push(_), n++);
@@ -1048,7 +1042,7 @@ class Q {
1048
1042
  this._trackable.addDependency = r;
1049
1043
  let o = !1;
1050
1044
  try {
1051
- const _ = y.run(this._trackable, this._fn);
1045
+ const _ = m.run(this._trackable, this._fn);
1052
1046
  if (t.length = n, X(_)) {
1053
1047
  this._syncDependencies(e, t, this._unsubscribes, s), this._dependencies = t, o = !0, this._handleAsyncComputation(_), this._setRecomputing(!1);
1054
1048
  return;
@@ -1057,7 +1051,7 @@ class Q {
1057
1051
  } catch (_) {
1058
1052
  t.length = n, this._syncDependencies(e, t, this._unsubscribes, s), this._dependencies = t, this._handleComputationError(_);
1059
1053
  } finally {
1060
- this._trackable.addDependency = c, o ? e !== f && g.release(e) : g.release(t);
1054
+ this._trackable.addDependency = c, o ? e !== f && S.release(e) : S.release(t);
1061
1055
  }
1062
1056
  }
1063
1057
  /**
@@ -1074,7 +1068,7 @@ class Q {
1074
1068
  const o = e[c];
1075
1069
  o && (o._tempUnsub = s[c]);
1076
1070
  }
1077
- const r = I.acquire();
1071
+ const r = y.acquire();
1078
1072
  r.length = t.length;
1079
1073
  for (let c = 0; c < t.length; c++) {
1080
1074
  const o = t[c];
@@ -1085,11 +1079,10 @@ class Q {
1085
1079
  const o = e[c];
1086
1080
  o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
1087
1081
  }
1088
- s !== E && I.release(s), this._unsubscribes = r;
1082
+ s !== E && y.release(s), this._unsubscribes = r;
1089
1083
  }
1090
1084
  _handleSyncResult(e) {
1091
- const t = !this._isResolved() || !this._equal(this._value, e);
1092
- this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), t && this._notifySubscribers();
1085
+ (!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & D), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
1093
1086
  }
1094
1087
  _handleAsyncComputation(e) {
1095
1088
  this._setPending(), this._promiseId = this._promiseId >= this.MAX_PROMISE_ID ? 1 : this._promiseId + 1;
@@ -1101,11 +1094,10 @@ class Q {
1101
1094
  });
1102
1095
  }
1103
1096
  _handleAsyncResolution(e) {
1104
- const t = !this._isResolved() || !this._equal(this._value, e);
1105
- this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), t && this._notifySubscribers();
1097
+ (!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & D), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
1106
1098
  }
1107
1099
  _handleAsyncRejection(e) {
1108
- const t = R(e, D, a.COMPUTED_ASYNC_COMPUTATION_FAILED);
1100
+ const t = R(e, I, a.COMPUTED_ASYNC_COMPUTATION_FAILED);
1109
1101
  if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError && typeof this._onError == "function")
1110
1102
  try {
1111
1103
  this._onError(t);
@@ -1115,7 +1107,7 @@ class Q {
1115
1107
  this._notifySubscribers();
1116
1108
  }
1117
1109
  _handleComputationError(e) {
1118
- const t = R(e, D, a.COMPUTED_COMPUTATION_FAILED);
1110
+ const t = R(e, I, a.COMPUTED_COMPUTATION_FAILED);
1119
1111
  if (this._error = t, this._setRejected(), this._clearDirty(), this._setRecomputing(!1), this._onError && typeof this._onError == "function")
1120
1112
  try {
1121
1113
  this._onError(t);
@@ -1127,7 +1119,7 @@ class Q {
1127
1119
  _handlePending() {
1128
1120
  if (this._hasDefaultValue)
1129
1121
  return this._defaultValue;
1130
- throw new D(a.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
1122
+ throw new I(a.COMPUTED_ASYNC_PENDING_NO_DEFAULT);
1131
1123
  }
1132
1124
  _handleRejected() {
1133
1125
  if (this._error?.recoverable && this._hasDefaultValue)
@@ -1144,14 +1136,29 @@ class Q {
1144
1136
  execute() {
1145
1137
  this._markDirty();
1146
1138
  }
1139
+ /**
1140
+ * Push-State, Pull-Value pattern:
1141
+ * Marks this computed as dirty and propagates to all subscribers.
1142
+ * - Object subscribers (Computed atoms): will mark themselves dirty
1143
+ * - Function subscribers (Effects): will schedule their execution
1144
+ * Actual recomputation happens lazily when .value is accessed (Pull).
1145
+ */
1147
1146
  _markDirty() {
1148
- this._isRecomputing() || this._isDirty() || (this._setDirty(), this._setIdle(), (this._functionSubscribers.hasSubscribers || this._objectSubscribers.hasSubscribers) && m.schedule(this._recomputeJob));
1147
+ this._isRecomputing() || this._isDirty() || (this._setDirty(), this._setIdle(), this._notifyJob());
1149
1148
  }
1149
+ /**
1150
+ * Notifies function subscribers (Effects) of state changes.
1151
+ * Currently only called from _handleAsyncRejection to notify Effects of errors.
1152
+ * In normal operation, Effects are notified via _markDirty during dirty propagation.
1153
+ */
1150
1154
  _notifySubscribers() {
1151
- !this._functionSubscribers.hasSubscribers && !this._objectSubscribers.hasSubscribers || m.schedule(this._notifyJob);
1155
+ this._functionSubscribers.hasSubscribers && this._functionSubscribers.forEachSafe(
1156
+ (e) => e(),
1157
+ (e) => console.error(e)
1158
+ );
1152
1159
  }
1153
1160
  _registerTracking() {
1154
- const e = y.getCurrent();
1161
+ const e = m.getCurrent();
1155
1162
  if (e)
1156
1163
  if (typeof e == "object" && e !== null && e.addDependency)
1157
1164
  e.addDependency(this);
@@ -1169,7 +1176,7 @@ class te {
1169
1176
  constructor(e, t = {}) {
1170
1177
  this.run = () => {
1171
1178
  if (this.isDisposed)
1172
- throw new S(a.EFFECT_MUST_BE_FUNCTION);
1179
+ throw new g(a.EFFECT_MUST_BE_FUNCTION);
1173
1180
  this.execute();
1174
1181
  }, this.dispose = () => {
1175
1182
  if (!this.isDisposed) {
@@ -1178,9 +1185,9 @@ class te {
1178
1185
  const n = this._unsubscribes[s];
1179
1186
  n && n();
1180
1187
  }
1181
- I.release(this._unsubscribes), this._unsubscribes = E;
1188
+ y.release(this._unsubscribes), this._unsubscribes = E;
1182
1189
  }
1183
- this._dependencies !== f && (g.release(this._dependencies), this._dependencies = f);
1190
+ this._dependencies !== f && (S.release(this._dependencies), this._dependencies = f);
1184
1191
  }
1185
1192
  }, this.addDependency = (s) => {
1186
1193
  if (this.isExecuting && this._nextDeps && this._nextUnsubs) {
@@ -1191,7 +1198,7 @@ class te {
1191
1198
  }, this.execute = () => {
1192
1199
  if (this.isDisposed || this.isExecuting) return;
1193
1200
  this._checkInfiniteLoop(), this._setExecuting(!0), this._safeCleanup();
1194
- const s = this._dependencies, n = this._unsubscribes, r = g.acquire(), c = I.acquire(), o = G();
1201
+ const s = this._dependencies, n = this._unsubscribes, r = S.acquire(), c = y.acquire(), o = G();
1195
1202
  if (s !== f && n !== E)
1196
1203
  for (let u = 0; u < s.length; u++) {
1197
1204
  const l = s[u];
@@ -1200,14 +1207,14 @@ class te {
1200
1207
  this._nextDeps = r, this._nextUnsubs = c, this._currentEpoch = o;
1201
1208
  let _ = !1;
1202
1209
  try {
1203
- const u = y.run(this, this._fn);
1210
+ const u = m.run(this, this._fn);
1204
1211
  this._dependencies = r, this._unsubscribes = c, _ = !0, this._checkLoopWarnings(), X(u) ? u.then((l) => {
1205
1212
  !this.isDisposed && typeof l == "function" && (this._cleanup = l);
1206
1213
  }).catch((l) => {
1207
- console.error(R(l, S, a.EFFECT_EXECUTION_FAILED));
1214
+ console.error(R(l, g, a.EFFECT_EXECUTION_FAILED));
1208
1215
  }) : this._cleanup = typeof u == "function" ? u : null;
1209
1216
  } catch (u) {
1210
- _ = !0, console.error(R(u, S, a.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
1217
+ _ = !0, console.error(R(u, g, a.EFFECT_EXECUTION_FAILED)), this._cleanup = null;
1211
1218
  } finally {
1212
1219
  if (this._setExecuting(!1), this._nextDeps = null, this._nextUnsubs = null, _) {
1213
1220
  if (s !== f) {
@@ -1215,21 +1222,21 @@ class te {
1215
1222
  const l = s[u];
1216
1223
  l?._tempUnsub && (l._tempUnsub(), l._tempUnsub = void 0);
1217
1224
  }
1218
- g.release(s);
1225
+ S.release(s);
1219
1226
  }
1220
- n !== E && I.release(n);
1227
+ n !== E && y.release(n);
1221
1228
  } else {
1222
- g.release(r);
1229
+ S.release(r);
1223
1230
  for (let u = 0; u < c.length; u++)
1224
1231
  c[u]?.();
1225
- if (I.release(c), s !== f)
1232
+ if (y.release(c), s !== f)
1226
1233
  for (let u = 0; u < s.length; u++) {
1227
1234
  const l = s[u];
1228
1235
  l && (l._tempUnsub = void 0);
1229
1236
  }
1230
1237
  }
1231
1238
  }
1232
- }, this._id = B() & N, this._flags = 0, this._currentEpoch = -1, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? U.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? U.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = f, this._unsubscribes = E, this._nextDeps = null, this._nextUnsubs = null, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._history = w ? [] : null, this._executionCount = 0, b.attachDebugInfo(this, "effect", this._id);
1239
+ }, this._id = B() & D, this._flags = 0, this._currentEpoch = -1, this._fn = e, this._sync = t.sync ?? !1, this._maxExecutions = t.maxExecutionsPerSecond ?? A.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = t.maxExecutionsPerFlush ?? A.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = t.trackModifications ?? !1, this._cleanup = null, this._dependencies = f, this._unsubscribes = E, this._nextDeps = null, this._nextUnsubs = null, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._history = M ? [] : null, this._executionCount = 0, b.attachDebugInfo(this, "effect", this._id);
1233
1240
  }
1234
1241
  /**
1235
1242
  * Synchronizes subscriptions by unsubscribing from removed dependencies.
@@ -1242,11 +1249,11 @@ class te {
1242
1249
  _subscribeTo(e) {
1243
1250
  try {
1244
1251
  const t = e.subscribe(() => {
1245
- this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : m.schedule(this.execute);
1252
+ this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : N.schedule(this.execute);
1246
1253
  });
1247
1254
  this._nextUnsubs && this._nextUnsubs.push(t);
1248
1255
  } catch (t) {
1249
- console.error(R(t, S, a.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
1256
+ console.error(R(t, g, a.EFFECT_EXECUTION_FAILED)), this._nextUnsubs && this._nextUnsubs.push(() => {
1250
1257
  });
1251
1258
  }
1252
1259
  }
@@ -1358,7 +1365,7 @@ class te {
1358
1365
  try {
1359
1366
  this._cleanup();
1360
1367
  } catch (e) {
1361
- console.error(R(e, S, a.EFFECT_CLEANUP_FAILED));
1368
+ console.error(R(e, g, a.EFFECT_CLEANUP_FAILED));
1362
1369
  }
1363
1370
  this._cleanup = null;
1364
1371
  }
@@ -1371,9 +1378,9 @@ class te {
1371
1378
  * @internal
1372
1379
  */
1373
1380
  _checkInfiniteLoop() {
1374
- if (this._lastFlushEpoch !== A && (this._lastFlushEpoch = A, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), H() > U.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
1381
+ if (this._lastFlushEpoch !== U && (this._lastFlushEpoch = U, this._executionsInEpoch = 0), this._executionsInEpoch++, this._executionsInEpoch > this._maxExecutionsPerFlush && this._throwInfiniteLoopError("per-effect"), H() > A.MAX_EXECUTIONS_PER_FLUSH && this._throwInfiniteLoopError("global"), this._executionCount++, this._history) {
1375
1382
  const e = Date.now();
1376
- this._history.push(e), this._history.length > U.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
1383
+ this._history.push(e), this._history.length > A.MAX_EXECUTIONS_PER_SECOND + 10 && this._history.shift(), this._checkTimestampLoop(e);
1377
1384
  }
1378
1385
  }
1379
1386
  _checkTimestampLoop(e) {
@@ -1384,16 +1391,16 @@ class te {
1384
1391
  for (let r = t.length - 1; r >= 0 && !(t[r] < s); r--)
1385
1392
  n++;
1386
1393
  if (n > this._maxExecutions) {
1387
- const r = new S(
1394
+ const r = new g(
1388
1395
  `Effect executed ${n} times within 1 second. Infinite loop suspected`
1389
1396
  );
1390
- if (this.dispose(), console.error(r), w)
1397
+ if (this.dispose(), console.error(r), M)
1391
1398
  throw r;
1392
1399
  }
1393
1400
  }
1394
1401
  _throwInfiniteLoopError(e) {
1395
- const t = new S(
1396
- `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${v}`
1402
+ const t = new g(
1403
+ `Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${w}`
1397
1404
  );
1398
1405
  throw this.dispose(), console.error(t), t;
1399
1406
  }
@@ -1425,7 +1432,7 @@ class te {
1425
1432
  }
1426
1433
  function he(i, e = {}) {
1427
1434
  if (typeof i != "function")
1428
- throw new S(a.EFFECT_MUST_BE_FUNCTION);
1435
+ throw new g(a.EFFECT_MUST_BE_FUNCTION);
1429
1436
  const t = new te(i, e);
1430
1437
  return t.execute(), t;
1431
1438
  }
@@ -1446,12 +1453,12 @@ function ae(i) {
1446
1453
  export {
1447
1454
  T as AsyncState,
1448
1455
  d as AtomError,
1449
- D as ComputedError,
1456
+ I as ComputedError,
1450
1457
  k as DEBUG_CONFIG,
1451
1458
  b as DEBUG_RUNTIME,
1452
- S as EffectError,
1459
+ g as EffectError,
1453
1460
  ie as POOL_CONFIG,
1454
- U as SCHEDULER_CONFIG,
1461
+ A as SCHEDULER_CONFIG,
1455
1462
  C as SchedulerError,
1456
1463
  ce as atom,
1457
1464
  ne as batch,
@@ -1460,7 +1467,7 @@ export {
1460
1467
  se as isAtom,
1461
1468
  oe as isComputed,
1462
1469
  ae as isEffect,
1463
- m as scheduler,
1470
+ N as scheduler,
1464
1471
  re as untracked
1465
1472
  };
1466
1473
  //# sourceMappingURL=index.mjs.map