atom-effect-jquery 0.3.0 → 0.4.0

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
@@ -3,12 +3,12 @@ import { default as ht } from "jquery";
3
3
  const Le = {
4
4
  /** One second in milliseconds */
5
5
  ONE_SECOND_MS: 1e3
6
- }, W = {
6
+ }, K = {
7
7
  IDLE: "idle",
8
8
  PENDING: "pending",
9
9
  RESOLVED: "resolved",
10
10
  REJECTED: "rejected"
11
- }, J = {
11
+ }, W = {
12
12
  DISPOSED: 1,
13
13
  // 0001 - Effect has been disposed
14
14
  EXECUTING: 2
@@ -389,15 +389,15 @@ class qe {
389
389
  this.maxFlushIterations = e;
390
390
  }
391
391
  }
392
- const K = new qe();
392
+ const J = new qe();
393
393
  function w(t) {
394
394
  if (typeof t != "function")
395
395
  throw new F("Batch callback must be a function");
396
- K.startBatch();
396
+ J.startBatch();
397
397
  try {
398
398
  return t();
399
399
  } finally {
400
- K.endBatch();
400
+ J.endBatch();
401
401
  }
402
402
  }
403
403
  const q = {
@@ -502,10 +502,10 @@ function ze(t) {
502
502
  function Ne(t) {
503
503
  return (typeof t == "object" || typeof t == "function") && t !== null && typeof t.addDependency == "function";
504
504
  }
505
- function Ue(t) {
505
+ function Te(t) {
506
506
  return typeof t == "function" && typeof t.addDependency != "function";
507
507
  }
508
- function Re(t) {
508
+ function Ue(t) {
509
509
  return ze(t) && typeof t.execute == "function";
510
510
  }
511
511
  class Xe extends Ie {
@@ -541,14 +541,14 @@ class Xe extends Ie {
541
541
  e.addDependency(this);
542
542
  return;
543
543
  }
544
- if (Ue(e)) {
544
+ if (Te(e)) {
545
545
  this._functionSubscribersStore.add(e);
546
546
  return;
547
547
  }
548
- Re(e) && this._objectSubscribersStore.add(e);
548
+ Ue(e) && this._objectSubscribersStore.add(e);
549
549
  }
550
550
  _scheduleNotification(e) {
551
- this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !K.isBatching ? this._flushNotifications() : K.schedule(this._notifyTask);
551
+ this._isNotificationScheduled || (this._pendingOldValue = e, this._isNotificationScheduled = !0), this._sync && !J.isBatching ? this._flushNotifications() : J.schedule(this._notifyTask);
552
552
  }
553
553
  _flushNotifications() {
554
554
  if (!this._isNotificationScheduled) return;
@@ -623,9 +623,9 @@ class ae {
623
623
  this.pool.length = 0, v && this.stats && (this.stats.acquired = 0, this.stats.released = 0, this.stats.rejected = { frozen: 0, tooLarge: 0, poolFull: 0 });
624
624
  }
625
625
  }
626
- const y = Object.freeze([]), R = Object.freeze([]), D = Object.freeze([]), P = new ae(), B = new ae(), T = new ae();
626
+ const y = Object.freeze([]), U = Object.freeze([]), D = Object.freeze([]), P = new ae(), B = new ae(), R = new ae();
627
627
  function Qe(t, e, n, s) {
628
- if (e !== y && n !== R)
628
+ if (e !== y && n !== U)
629
629
  for (let r = 0; r < e.length; r++) {
630
630
  const o = e[r];
631
631
  o && (o._tempUnsub = n[r]);
@@ -641,7 +641,7 @@ function Qe(t, e, n, s) {
641
641
  const o = e[r];
642
642
  o?._tempUnsub && (o._tempUnsub(), o._tempUnsub = void 0);
643
643
  }
644
- return n !== R && B.release(n), i;
644
+ return n !== U && B.release(n), i;
645
645
  }
646
646
  function G(t, e, n) {
647
647
  if (t instanceof TypeError)
@@ -653,11 +653,11 @@ function G(t, e, n) {
653
653
  const s = t instanceof Error ? t.message : String(t), i = t instanceof Error ? t : null;
654
654
  return new e(`Unexpected error (${n}): ${s}`, i);
655
655
  }
656
- class Te extends Ie {
656
+ class Re extends Ie {
657
657
  constructor(e, n = {}) {
658
658
  if (typeof e != "function")
659
659
  throw new X(E.COMPUTED_MUST_BE_FUNCTION);
660
- if (super(), this._value = void 0, this.flags = p.DIRTY | p.IDLE, this._error = null, this._promiseId = 0, this._equal = n.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in n ? n.defaultValue : pe, this._hasDefaultValue = this._defaultValue !== pe, this._onError = n.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new ne(), this._objectSubscribersStore = new ne(), this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = R, this._notifyJob = () => {
660
+ if (super(), this._value = void 0, this.flags = p.DIRTY | p.IDLE, this._error = null, this._promiseId = 0, this._equal = n.equal ?? Object.is, this._fn = e, this._defaultValue = "defaultValue" in n ? n.defaultValue : pe, this._hasDefaultValue = this._defaultValue !== pe, this._onError = n.onError ?? null, this.MAX_PROMISE_ID = Number.MAX_SAFE_INTEGER - 1, this._functionSubscribersStore = new ne(), this._objectSubscribersStore = new ne(), this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = U, this._notifyJob = () => {
661
661
  this._functionSubscribersStore.forEachSafe(
662
662
  (s) => s(),
663
663
  (s) => console.error(s)
@@ -692,32 +692,32 @@ class Te extends Ie {
692
692
  return this._value;
693
693
  }
694
694
  get state() {
695
- return this._getAsyncState();
695
+ return this._registerTracking(), this._getAsyncState();
696
696
  }
697
697
  get hasError() {
698
- return this._isRejected();
698
+ return this._registerTracking(), this._isRejected();
699
699
  }
700
700
  get lastError() {
701
- return this._error;
701
+ return this._registerTracking(), this._error;
702
702
  }
703
703
  get isPending() {
704
- return this._isPending();
704
+ return this._registerTracking(), this._isPending();
705
705
  }
706
706
  get isResolved() {
707
- return this._isResolved();
707
+ return this._registerTracking(), this._isResolved();
708
708
  }
709
709
  invalidate() {
710
- this._markDirty(), this._dependencyVersions !== D && (T.release(this._dependencyVersions), this._dependencyVersions = D);
710
+ this._markDirty(), this._dependencyVersions !== D && (R.release(this._dependencyVersions), this._dependencyVersions = D);
711
711
  }
712
712
  dispose() {
713
- if (this._unsubscribes !== R) {
713
+ if (this._unsubscribes !== U) {
714
714
  for (let e = 0; e < this._unsubscribes.length; e++) {
715
715
  const n = this._unsubscribes[e];
716
716
  n && n();
717
717
  }
718
- B.release(this._unsubscribes), this._unsubscribes = R;
718
+ B.release(this._unsubscribes), this._unsubscribes = U;
719
719
  }
720
- this._dependencies !== y && (P.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (T.release(this._dependencyVersions), this._dependencyVersions = D), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = p.DIRTY | p.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
720
+ this._dependencies !== y && (P.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (R.release(this._dependencyVersions), this._dependencyVersions = D), this._functionSubscribersStore.clear(), this._objectSubscribersStore.clear(), this.flags = p.DIRTY | p.IDLE, this._error = null, this._value = void 0, this._promiseId = (this._promiseId + 1) % this.MAX_PROMISE_ID;
721
721
  }
722
722
  // State flag operations
723
723
  _isDirty() {
@@ -761,7 +761,7 @@ class Te extends Ie {
761
761
  this.flags = this.flags & ~n | -Number(e) & n;
762
762
  }
763
763
  _getAsyncState() {
764
- return this._isResolved() ? W.RESOLVED : this._isPending() ? W.PENDING : this._isRejected() ? W.REJECTED : W.IDLE;
764
+ return this._isResolved() ? K.RESOLVED : this._isPending() ? K.PENDING : this._isRejected() ? K.REJECTED : K.IDLE;
765
765
  }
766
766
  _getFlagsAsString() {
767
767
  const e = [];
@@ -785,7 +785,7 @@ class Te extends Ie {
785
785
  }
786
786
  }
787
787
  _prepareComputationContext() {
788
- const e = this._dependencies, n = this._dependencyVersions, s = P.acquire(), i = T.acquire(), r = xe(), o = { depCount: 0 }, u = (f) => {
788
+ const e = this._dependencies, n = this._dependencyVersions, s = P.acquire(), i = R.acquire(), r = xe(), o = { depCount: 0 }, u = (f) => {
789
789
  f._lastSeenEpoch !== r && (f._lastSeenEpoch = r, o.depCount < s.length ? (s[o.depCount] = f, i[o.depCount] = f.version) : (s.push(f), i.push(f.version)), o.depCount++);
790
790
  }, l = this._trackable.addDependency;
791
791
  return this._trackable.addDependency = u, { prevDeps: e, prevVersions: n, nextDeps: s, nextVersions: i, originalAdd: l, state: o };
@@ -795,7 +795,7 @@ class Te extends Ie {
795
795
  n.length = i.depCount, s.length = i.depCount, this._unsubscribes = Qe(n, r, this._unsubscribes, this), this._dependencies = n, this._dependencyVersions = s;
796
796
  }
797
797
  _cleanupContext(e, n) {
798
- this._trackable.addDependency = e.originalAdd, n ? (e.prevDeps !== y && P.release(e.prevDeps), e.prevVersions !== D && T.release(e.prevVersions)) : (P.release(e.nextDeps), T.release(e.nextVersions));
798
+ this._trackable.addDependency = e.originalAdd, n ? (e.prevDeps !== y && P.release(e.prevDeps), e.prevVersions !== D && R.release(e.prevVersions)) : (P.release(e.nextDeps), R.release(e.nextVersions));
799
799
  }
800
800
  _handleSyncResult(e) {
801
801
  (!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & Q), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
@@ -810,7 +810,7 @@ class Te extends Ie {
810
810
  });
811
811
  }
812
812
  _handleAsyncResolution(e) {
813
- (!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & Q), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1);
813
+ (!this._isResolved() || !this._equal(this._value, e)) && (this.version = this.version + 1 & Q), this._value = e, this._clearDirty(), this._setResolved(), this._error = null, this._setRecomputing(!1), this._notifyJob();
814
814
  }
815
815
  _handleAsyncRejection(e) {
816
816
  const n = G(e, X, E.COMPUTED_ASYNC_COMPUTATION_FAILED);
@@ -856,17 +856,17 @@ class Te extends Ie {
856
856
  e.addDependency(this);
857
857
  return;
858
858
  }
859
- if (Ue(e)) {
859
+ if (Te(e)) {
860
860
  this._functionSubscribersStore.add(e);
861
861
  return;
862
862
  }
863
- Re(e) && this._objectSubscribersStore.add(e);
863
+ Ue(e) && this._objectSubscribersStore.add(e);
864
864
  }
865
865
  }
866
866
  }
867
- Object.freeze(Te.prototype);
867
+ Object.freeze(Re.prototype);
868
868
  function He(t, e = {}) {
869
- return new Te(t, e);
869
+ return new Re(t, e);
870
870
  }
871
871
  class Ye extends De {
872
872
  /**
@@ -878,17 +878,17 @@ class Ye extends De {
878
878
  super(), this.run = () => {
879
879
  if (this.isDisposed)
880
880
  throw new L(E.EFFECT_MUST_BE_FUNCTION);
881
- this._dependencyVersions !== D && (T.release(this._dependencyVersions), this._dependencyVersions = D), this.execute();
881
+ this._dependencyVersions !== D && (R.release(this._dependencyVersions), this._dependencyVersions = D), this.execute();
882
882
  }, this.dispose = () => {
883
883
  if (!this.isDisposed) {
884
- if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== R) {
884
+ if (this._setDisposed(), this._safeCleanup(), this._unsubscribes !== U) {
885
885
  for (let s = 0; s < this._unsubscribes.length; s++) {
886
886
  const i = this._unsubscribes[s];
887
887
  i && i();
888
888
  }
889
- B.release(this._unsubscribes), this._unsubscribes = R;
889
+ B.release(this._unsubscribes), this._unsubscribes = U;
890
890
  }
891
- this._dependencies !== y && (P.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (T.release(this._dependencyVersions), this._dependencyVersions = D);
891
+ this._dependencies !== y && (P.release(this._dependencies), this._dependencies = y), this._dependencyVersions !== D && (R.release(this._dependencyVersions), this._dependencyVersions = D);
892
892
  }
893
893
  }, this.addDependency = (s) => {
894
894
  if (this.isExecuting && this._nextDeps && this._nextUnsubs && this._nextVersions) {
@@ -913,15 +913,15 @@ class Ye extends De {
913
913
  } finally {
914
914
  this._cleanupEffect(s, i), this._setExecuting(!1);
915
915
  }
916
- }, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = n.sync ?? !1, this._maxExecutions = n.maxExecutionsPerSecond ?? $.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = n.maxExecutionsPerFlush ?? $.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = n.trackModifications ?? !1, this._cleanup = null, this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = R, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = v ? [] : null, this._executionCount = 0, O.attachDebugInfo(this, "effect", this.id);
916
+ }, this._currentEpoch = -1, this._lastFlushEpoch = -1, this._executionsInEpoch = 0, this._fn = e, this._sync = n.sync ?? !1, this._maxExecutions = n.maxExecutionsPerSecond ?? $.MAX_EXECUTIONS_PER_SECOND, this._maxExecutionsPerFlush = n.maxExecutionsPerFlush ?? $.MAX_EXECUTIONS_PER_EFFECT, this._trackModifications = n.trackModifications ?? !1, this._cleanup = null, this._dependencies = y, this._dependencyVersions = D, this._unsubscribes = U, this._nextDeps = null, this._nextVersions = null, this._nextUnsubs = null, this._history = v ? [] : null, this._executionCount = 0, O.attachDebugInfo(this, "effect", this.id);
917
917
  }
918
918
  /**
919
919
  * Prepares the execution context by acquiring pools and setting up epoch.
920
920
  * @returns The prepared EffectContext.
921
921
  */
922
922
  _prepareEffectContext() {
923
- const e = this._dependencies, n = this._dependencyVersions, s = this._unsubscribes, i = P.acquire(), r = T.acquire(), o = B.acquire(), u = xe();
924
- if (e !== y && s !== R)
923
+ const e = this._dependencies, n = this._dependencyVersions, s = this._unsubscribes, i = P.acquire(), r = R.acquire(), o = B.acquire(), u = xe();
924
+ if (e !== y && s !== U)
925
925
  for (let l = 0; l < e.length; l++) {
926
926
  const f = e[l];
927
927
  f && (f._tempUnsub = s[l]);
@@ -950,9 +950,9 @@ class Ye extends De {
950
950
  }
951
951
  P.release(e.prevDeps);
952
952
  }
953
- e.prevUnsubs !== R && B.release(e.prevUnsubs), e.prevVersions !== D && T.release(e.prevVersions);
953
+ e.prevUnsubs !== U && B.release(e.prevUnsubs), e.prevVersions !== D && R.release(e.prevVersions);
954
954
  } else {
955
- P.release(e.nextDeps), T.release(e.nextVersions);
955
+ P.release(e.nextDeps), R.release(e.nextVersions);
956
956
  for (let s = 0; s < e.nextUnsubs.length; s++)
957
957
  e.nextUnsubs[s]?.();
958
958
  if (B.release(e.nextUnsubs), e.prevDeps !== y)
@@ -969,7 +969,7 @@ class Ye extends De {
969
969
  _subscribeTo(e) {
970
970
  try {
971
971
  const n = e.subscribe(() => {
972
- this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : K.schedule(this.execute);
972
+ this._trackModifications && this.isExecuting && (e._modifiedAtEpoch = this._currentEpoch), this._sync ? this.execute() : J.schedule(this.execute);
973
973
  });
974
974
  this._nextUnsubs && this._nextUnsubs.push(n);
975
975
  } catch (n) {
@@ -981,7 +981,7 @@ class Ye extends De {
981
981
  * Whether the effect has been disposed.
982
982
  */
983
983
  get isDisposed() {
984
- return (this.flags & J.DISPOSED) !== 0;
984
+ return (this.flags & W.DISPOSED) !== 0;
985
985
  }
986
986
  /**
987
987
  * Total number of times this effect has executed.
@@ -993,13 +993,13 @@ class Ye extends De {
993
993
  * Whether the effect is currently executing.
994
994
  */
995
995
  get isExecuting() {
996
- return (this.flags & J.EXECUTING) !== 0;
996
+ return (this.flags & W.EXECUTING) !== 0;
997
997
  }
998
998
  _setDisposed() {
999
- this.flags |= J.DISPOSED;
999
+ this.flags |= W.DISPOSED;
1000
1000
  }
1001
1001
  _setExecuting(e) {
1002
- const n = J.EXECUTING;
1002
+ const n = W.EXECUTING;
1003
1003
  this.flags = this.flags & ~n | -Number(e) & n;
1004
1004
  }
1005
1005
  /**
@@ -1091,7 +1091,7 @@ function I(t, e = {}) {
1091
1091
  const n = new Ye(t, e);
1092
1092
  return n.execute(), n;
1093
1093
  }
1094
- function Ke() {
1094
+ function Je() {
1095
1095
  if (typeof window < "u") {
1096
1096
  const t = window.__ATOM_DEBUG__;
1097
1097
  if (typeof t == "boolean")
@@ -1104,7 +1104,7 @@ function Ke() {
1104
1104
  }
1105
1105
  return !1;
1106
1106
  }
1107
- let V = Ke();
1107
+ let V = Je();
1108
1108
  const h = {
1109
1109
  get enabled() {
1110
1110
  return V;
@@ -1128,11 +1128,11 @@ const h = {
1128
1128
  */
1129
1129
  domUpdated(t, e, n) {
1130
1130
  if (!V) return;
1131
- const s = We(t);
1131
+ const s = Ke(t);
1132
1132
  console.log(
1133
1133
  `[atom-effect-jquery] DOM updated: ${s}.${e} =`,
1134
1134
  n
1135
- ), Je(t);
1135
+ ), We(t);
1136
1136
  },
1137
1137
  cleanup(t) {
1138
1138
  V && console.log(`[atom-effect-jquery] Cleanup: ${t}`);
@@ -1141,7 +1141,7 @@ const h = {
1141
1141
  V && console.warn("[atom-effect-jquery]", ...t);
1142
1142
  }
1143
1143
  };
1144
- function We(t) {
1144
+ function Ke(t) {
1145
1145
  const e = t[0];
1146
1146
  if (!e) return "unknown";
1147
1147
  if (e.id) return `#${e.id}`;
@@ -1151,7 +1151,7 @@ function We(t) {
1151
1151
  }
1152
1152
  return e.tagName.toLowerCase();
1153
1153
  }
1154
- function Je(t) {
1154
+ function We(t) {
1155
1155
  const e = t[0];
1156
1156
  if (!e || !document.contains(e)) return;
1157
1157
  const n = "atom_debug_timer", s = "atom_debug_cleanup_timer", i = "atom_debug_org_style";
@@ -1618,7 +1618,7 @@ c.fn.atomList = function(t, e) {
1618
1618
  const ie = /* @__PURE__ */ new Map();
1619
1619
  j.forEach((d, S) => ie.set(d, S));
1620
1620
  const we = k.map((d) => ie.has(d) ? ie.get(d) : -1), Fe = nt(we), ke = new Set(Fe);
1621
- let U = null;
1621
+ let T = null;
1622
1622
  for (let d = N.length - 1; d >= 0; d--) {
1623
1623
  const S = k[d], M = N[d], Me = ke.has(d);
1624
1624
  if (m.has(S)) {
@@ -1626,15 +1626,15 @@ c.fn.atomList = function(t, e) {
1626
1626
  C.item = M;
1627
1627
  const A = C.$el[0];
1628
1628
  if (e.update && e.update(C.$el, M, d), !Me)
1629
- U ? C.$el.insertBefore(U) : C.$el.appendTo(n);
1629
+ T ? C.$el.insertBefore(T) : C.$el.appendTo(n);
1630
1630
  else {
1631
1631
  const de = A.nextSibling;
1632
- U && de !== U ? C.$el.insertBefore(U) : !U && de && C.$el.appendTo(n);
1632
+ T && de !== T ? C.$el.insertBefore(T) : !T && de && C.$el.appendTo(n);
1633
1633
  }
1634
- U = A;
1634
+ T = A;
1635
1635
  } else {
1636
1636
  const C = r(M, d), A = C instanceof Element ? c(C) : c(C);
1637
- m.set(S, { $el: A, item: M }), U ? A.insertBefore(U) : A.appendTo(n), o && o(A, M, d), u && u(A), h.log("list", `${s} added item:`, S), U = A[0];
1637
+ m.set(S, { $el: A, item: M }), T ? A.insertBefore(T) : A.appendTo(n), o && o(A, M, d), u && u(A), h.log("list", `${s} added item:`, S), T = A[0];
1638
1638
  }
1639
1639
  }
1640
1640
  j = k;