@oscarpalmer/mora 0.33.0 → 0.35.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.
@@ -125,10 +125,10 @@ function emitValue(instance) {
125
125
  }
126
126
  if (BATCH.depth === 0) flushHandlers();
127
127
  }
128
- function equalArrays(state, first, second) {
128
+ function equalArrays(first, second, equal) {
129
129
  const { length } = first;
130
130
  if (length !== second.length) return false;
131
- const eq = state.equal ?? Object.is;
131
+ const eq = equal ?? Object.is;
132
132
  let offset = 0;
133
133
  if (length >= 100) {
134
134
  offset = Math.round(length / 10);
@@ -145,21 +145,25 @@ function getFrozenValue(value) {
145
145
  else if (isPlainObject(frozen)) frozen = Object.freeze({ ...frozen });
146
146
  return frozen;
147
147
  }
148
+ function getJsonValue() {
149
+ return this[SYMBOL_STATE].value;
150
+ }
148
151
  function getSignalValue() {
152
+ const state = this[SYMBOL_STATE];
149
153
  if (ACTIVE.computed != null) {
150
- this[SYMBOL_STATE].computeds ??= /* @__PURE__ */ new Set();
151
- this[SYMBOL_STATE].computeds.add(ACTIVE.computed);
154
+ state.computeds ??= /* @__PURE__ */ new Set();
155
+ state.computeds.add(ACTIVE.computed);
152
156
  }
153
157
  if (ACTIVE.effect != null) {
154
- this[SYMBOL_STATE].effects ??= /* @__PURE__ */ new Set();
155
- this[SYMBOL_STATE].effects.add(ACTIVE.effect);
158
+ state.effects ??= /* @__PURE__ */ new Set();
159
+ state.effects.add(ACTIVE.effect);
156
160
  }
157
- return this[SYMBOL_STATE].value;
161
+ return state.value;
158
162
  }
159
163
  function getStringValue(json) {
160
164
  return json === true ? JSON.stringify(this[SYMBOL_STATE].value) : String(this[SYMBOL_STATE].value);
161
165
  }
162
- function handleSignalValue(instance, origin, setValue, onAfter) {
166
+ function handleSignal(instance, origin, setValue, onAfter) {
163
167
  const state = instance[SYMBOL_STATE];
164
168
  try {
165
169
  let actual = typeof origin === "function" ? origin() : origin;
@@ -185,9 +189,9 @@ function peekSignalValue(copy) {
185
189
  else if (isPlainObject(peeked)) peeked = { ...peeked };
186
190
  return peeked;
187
191
  }
188
- function updateSignalValue(instance, callback, setValue) {
192
+ function updateSignal(instance, callback, setValue) {
189
193
  if (typeof callback !== "function") throw new TypeError("Callback must be a function");
190
- handleSignalValue(instance, callback(instance[SYMBOL_STATE].value), setValue);
194
+ handleSignal(instance, callback(instance[SYMBOL_STATE].value), setValue);
191
195
  }
192
196
  //#endregion
193
197
  //#region src/batch.ts
@@ -464,13 +468,54 @@ const ABORT_EVENT = "abort";
464
468
  const ABORT_OPTIONS = { once: true };
465
469
  //#endregion
466
470
  //#region node_modules/@oscarpalmer/atoms/dist/internal/subscription.mjs
467
- function addSubscription(subscriptions, subscription, state) {
468
- const { items, values } = subscriptions;
471
+ const SUBSCRIPTION_NAME = "subscription";
472
+ const SUBSCRIPTION_PROPERTY = "$subscription";
473
+ const SUBSCRIPTION_STORE = "subscriptions";
474
+ function Subscription(state, property, parameters) {
475
+ Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: state });
476
+ state.aborter = createAborter(parameters.signal, () => this.unsubscribe(subscriptions, this, state));
477
+ Object.defineProperties(this, {
478
+ [property.key]: { value: property.value },
479
+ active: {
480
+ enumerable: true,
481
+ get: () => (state.parameters?.isActive?.() ?? true) && state.active
482
+ }
483
+ });
484
+ addSubscription(this);
485
+ }
486
+ Object.defineProperties(Subscription.prototype, {
487
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
488
+ unsubscribe: { value: removeSubscription }
489
+ });
490
+ function Subscriptions(parameters) {
491
+ const { keys, property } = createSubscriptionsParameters(parameters);
492
+ Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: createSubscriptionsState(property, keys) });
493
+ }
494
+ Object.defineProperties(Subscriptions.prototype, {
495
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
496
+ clear: { value: clearSubscriptions },
497
+ create: { value: createSubscription },
498
+ items: {
499
+ enumerable: true,
500
+ get() {
501
+ return this[SUBSCRIPTION_SYMBOL].items;
502
+ }
503
+ },
504
+ values: {
505
+ enumerable: true,
506
+ get() {
507
+ return this[SUBSCRIPTION_SYMBOL].values;
508
+ }
509
+ }
510
+ });
511
+ function addSubscription(instance) {
512
+ const state = instance[SUBSCRIPTION_SYMBOL];
469
513
  const { key, value } = state.parameters;
514
+ const { items, values } = state.subscriptions;
470
515
  if (!isKey(key)) {
471
- items.any.add(subscription);
472
- values.from.any.set(value, subscription);
473
- values.to.any.set(subscription, value);
516
+ items.any.add(instance);
517
+ values.from.any.set(value, instance);
518
+ values.to.any.set(instance, value);
474
519
  return;
475
520
  }
476
521
  /* istanbul ignore if */
@@ -482,29 +527,32 @@ function addSubscription(subscriptions, subscription, state) {
482
527
  keyedItems = /* @__PURE__ */ new Set();
483
528
  items.keyed.set(key, keyedItems);
484
529
  }
485
- keyedItems.add(subscription);
530
+ keyedItems.add(instance);
486
531
  let keyedFrom = values.from.keyed.get(key);
487
532
  if (keyedFrom == null) {
488
533
  keyedFrom = /* @__PURE__ */ new Map();
489
534
  values.from.keyed.set(key, keyedFrom);
490
535
  }
491
- keyedFrom.set(value, subscription);
536
+ keyedFrom.set(value, instance);
492
537
  let keyedTo = values.to.keyed.get(key);
493
538
  if (keyedTo == null) {
494
539
  keyedTo = /* @__PURE__ */ new Map();
495
540
  values.to.keyed.set(key, keyedTo);
496
541
  }
497
- keyedTo.set(subscription, value);
542
+ keyedTo.set(instance, value);
498
543
  }
499
- function clearSubscriptions(store) {
500
- for (const susbcription of store.values.to.any.keys()) susbcription.unsubscribe();
501
- if (store.values.to.keyed != null) for (const values of store.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
544
+ function clearSubscriptions() {
545
+ const state = this[SUBSCRIPTION_SYMBOL];
546
+ for (const susbcription of state.values.to.any.keys()) susbcription.unsubscribe();
547
+ if (state.values.to.keyed != null && state.values.to.keyed.size > 0) for (const values of state.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
502
548
  }
503
- function createSubscription(subscriptions, property, params) {
549
+ function createSubscription(params) {
504
550
  const parameters = createSubscriptionParameters(params);
505
551
  if (parameters.signal?.aborted ?? false) throw new Error(parameters.signal?.reason);
552
+ const subscriptions = this[SUBSCRIPTION_SYMBOL];
506
553
  const state = {
507
554
  parameters,
555
+ subscriptions,
508
556
  active: true
509
557
  };
510
558
  const existing = getExistingSubscription(subscriptions, state);
@@ -513,18 +561,7 @@ function createSubscription(subscriptions, property, params) {
513
561
  if (subscriptions.keys === false) throw new Error(SUBSCRIPTION_DISALLOWED_KEY);
514
562
  else if (subscriptions.keys !== true && !subscriptions.keys.has(parameters.key)) throw new Error(SUBSCRIPTION_INVALID_KEY);
515
563
  }
516
- state.aborter = createAborter(parameters.signal, () => unsubscribe(subscriptions, instance, state));
517
- const instance = { unsubscribe: () => unsubscribe(subscriptions, instance, state) };
518
- Object.defineProperties(instance, {
519
- [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
520
- [property.key]: { value: property.value },
521
- active: {
522
- enumerable: true,
523
- get: () => (parameters.isActive?.() ?? true) && state.active
524
- }
525
- });
526
- addSubscription(subscriptions, instance, state);
527
- return [Object.freeze(instance), false];
564
+ return [new Subscription(state, subscriptions.property, parameters), false];
528
565
  }
529
566
  function getExistingSubscription(subscriptions, state) {
530
567
  const { values } = subscriptions;
@@ -558,9 +595,10 @@ function createSubscriptionsProperty(input) {
558
595
  value: values.value == null ? SUBSCRIPTION_NAME : values.value
559
596
  };
560
597
  }
561
- function createSubscriptionsState(keys) {
598
+ function createSubscriptionsState(property, keys) {
562
599
  return {
563
600
  keys,
601
+ property,
564
602
  items: {
565
603
  any: /* @__PURE__ */ new Set(),
566
604
  keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
@@ -587,16 +625,17 @@ function removeFromStore(items, values, subscription, value, key) {
587
625
  values.to.keyed?.get(key)?.delete(subscription);
588
626
  }
589
627
  }
590
- function removeSubscription(subscriptionsState, subscription, state) {
628
+ function removeSubscription() {
629
+ const state = this[SUBSCRIPTION_SYMBOL];
591
630
  if (!state.active) return;
592
631
  state.aborter = void 0;
593
632
  state.active = false;
594
- state.parameters.isActive = void 0;
595
- state.parameters.signal = void 0;
596
- const { items, values } = subscriptionsState;
633
+ const { items, values } = state.subscriptions;
597
634
  const { key, value } = state.parameters;
635
+ state.parameters = void 0;
636
+ state.subscriptions = void 0;
598
637
  if (!isKey(key)) {
599
- removeFromStore(items.any, values, subscription, value);
638
+ removeFromStore(items.any, values, this, value);
600
639
  return;
601
640
  }
602
641
  const keyed = items.keyed?.get(key);
@@ -604,7 +643,7 @@ function removeSubscription(subscriptionsState, subscription, state) {
604
643
  if (items.keyed == null || keyed == null)
605
644
  // istanbul ignore next
606
645
  return;
607
- removeFromStore(keyed, values, subscription, value, key);
646
+ removeFromStore(keyed, values, this, value, key);
608
647
  if (keyed.size === 0) items.keyed.delete(key);
609
648
  }
610
649
  /**
@@ -614,35 +653,12 @@ function removeSubscription(subscriptionsState, subscription, state) {
614
653
  * @returns Subscription store
615
654
  */
616
655
  function subscriptions(parameters) {
617
- const { keys, property } = createSubscriptionsParameters(parameters);
618
- const state = createSubscriptionsState(keys);
619
- const instance = {
620
- clear: () => clearSubscriptions(state),
621
- create: (parameters) => createSubscription(state, property, parameters)
622
- };
623
- Object.defineProperties(instance, {
624
- [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
625
- items: {
626
- enumerable: true,
627
- value: state.items
628
- },
629
- values: {
630
- enumerable: true,
631
- value: state.values
632
- }
633
- });
634
- return Object.freeze(instance);
635
- }
636
- function unsubscribe(subscriptionsState, subscription, state) {
637
- state.aborter?.cancel();
638
- removeSubscription(subscriptionsState, subscription, state);
656
+ return new Subscriptions(parameters);
639
657
  }
640
658
  const SUBSCRIPTION_DISALLOWED_KEY = "Disallowed key for subscription";
641
659
  const SUBSCRIPTION_INVALID_KEY = "Invalid key for subscription";
642
660
  const SUBSCRIPTION_INVALID_VALUE = "A subscription requires a non-null value to identify it";
643
- const SUBSCRIPTION_NAME = "subscription";
644
- const SUBSCRIPTION_PROPERTY = "$subscriptions";
645
- const SUBSCRIPTION_STORE = "subscriptions";
661
+ const SUBSCRIPTION_SYMBOL = Symbol(SUBSCRIPTION_PROPERTY);
646
662
  //#endregion
647
663
  //#region src/helpers/subscription.ts
648
664
  function subscribeToProxy(first, second, third) {
@@ -677,10 +693,8 @@ Computed.prototype[NAME_MORA] = NAME_COMPUTED;
677
693
  Computed.prototype.get = getComputedValue;
678
694
  Computed.prototype.peek = peekSignalValue;
679
695
  Computed.prototype.subscribe = subscribeToSignal;
696
+ Computed.prototype.toJSON = getJsonValue;
680
697
  Computed.prototype.toString = getStringValue;
681
- Computed.prototype.toJSON = function() {
682
- return this[SYMBOL_STATE].value;
683
- };
684
698
  /**
685
699
  * Create a computed value
686
700
  *
@@ -705,7 +719,7 @@ function getComputedEffect(instance, callback) {
705
719
  if (fx.dirty) {
706
720
  const previousComputed = ACTIVE.computed;
707
721
  ACTIVE.computed = fx;
708
- handleSignalValue(instance, callback, setAndEmit$1, () => {
722
+ handleSignal(instance, callback, setAndEmit$1, () => {
709
723
  ACTIVE.computed = previousComputed;
710
724
  });
711
725
  fx.dirty = false;
@@ -768,8 +782,12 @@ function getReactiveValueInProxy(instance, key) {
768
782
  return item[0];
769
783
  }
770
784
  function getValueInProxy(first) {
771
- if (this[SYMBOL_STATE].isArray ? typeof first === "number" : isKey(first)) return getReactiveValueInProxy(this, first).get();
772
- return getSignalValue.call(this);
785
+ let signal;
786
+ if (this[SYMBOL_STATE].isArray ? typeof first === "number" : isKey(first)) signal = getReactiveValueInProxy(this, first);
787
+ return getSignalValue.call(signal ?? this);
788
+ }
789
+ function isProxyKey(isArray, value) {
790
+ return isArray ? typeof value === "number" : isKey(value);
773
791
  }
774
792
  function isProxyObject(isArray, value) {
775
793
  return value == null || (isArray ? Array.isArray(value) : isPlainObject(value));
@@ -783,23 +801,24 @@ function peekValueInProxy(first, second) {
783
801
  }
784
802
  function setProxyObject(state, value) {
785
803
  if (state.isArray) {
786
- state.value.splice(0, state.value.length, ...value ?? []);
804
+ const values = state.value;
805
+ values.splice(0, values.length, ...value ?? []);
787
806
  return;
788
807
  }
789
808
  startBatch();
790
- const actual = value ?? {};
791
- const proxy = state.value;
792
- const proxyKeys = Object.keys(proxy);
793
- const actualKeys = Object.keys(actual);
794
- let { length } = proxyKeys;
809
+ const current = state.value;
810
+ const next = value ?? {};
811
+ const currentKeys = Object.keys(current);
812
+ const nextKeys = Object.keys(next);
813
+ let { length } = currentKeys;
795
814
  for (let index = 0; index < length; index += 1) {
796
- const key = proxyKeys[index];
797
- proxy[key] = actualKeys.includes(key) ? actual[key] : void 0;
815
+ const key = currentKeys[index];
816
+ current[key] = nextKeys.includes(key) ? next[key] : void 0;
798
817
  }
799
- length = actualKeys.length;
818
+ length = nextKeys.length;
800
819
  for (let index = 0; index < length; index += 1) {
801
- const key = actualKeys[index];
802
- if (!proxyKeys.includes(key)) proxy[key] = actual[key];
820
+ const key = nextKeys[index];
821
+ if (!currentKeys.includes(key)) current[key] = next[key];
803
822
  }
804
823
  stopBatch();
805
824
  }
@@ -808,8 +827,10 @@ function setProxyProperty(state, property, value) {
808
827
  state.value[property] = value;
809
828
  return;
810
829
  }
811
- const actual = property < 0 ? state.value.length + property : property;
812
- if (actual > -1) state.value[actual] = value;
830
+ const array = state.value;
831
+ const index = property;
832
+ const actual = index < 0 ? array.length + index : index;
833
+ if (actual > -1) array[actual] = value;
813
834
  }
814
835
  function setProxyValue(first, second) {
815
836
  const state = this[SYMBOL_STATE];
@@ -821,34 +842,34 @@ function setProxyValue(first, second) {
821
842
  setProxyObject(state, first);
822
843
  return;
823
844
  }
824
- const property = state.isArray ? typeof first === "number" : isKey(first);
825
- if (state.isArray && property && Number.isNaN(first)) return;
826
- let actual = property ? second : first;
845
+ const keyed = isProxyKey(state.isArray, first);
846
+ if (state.isArray && keyed && Number.isNaN(first)) return;
847
+ let actual = keyed ? second : first;
827
848
  if (typeof actual === "function") try {
828
849
  actual = actual();
829
850
  } catch {
830
851
  return;
831
852
  }
832
853
  if (actual instanceof Promise) {
833
- if (property) {
854
+ if (keyed) {
834
855
  state.promises ??= /* @__PURE__ */ new Map();
835
856
  state.promises.set(first, actual);
836
857
  } else state.promise = actual;
837
858
  actual.then((value) => {
838
- if (property && state.promises.get(first) === actual) {
839
- state.promises.delete(first);
859
+ if (keyed && state.promises?.get(first) === actual) {
860
+ state.promises?.delete(first);
840
861
  setProxyProperty(state, first, value);
841
862
  return;
842
863
  }
843
- if (!property && isProxyObject(state.isArray, value) && state.promise === actual) {
864
+ if (!keyed && isProxyObject(state.isArray, value) && state.promise === actual) {
844
865
  state.promise = void 0;
845
866
  setProxyObject(state, value);
846
867
  }
847
868
  }).catch(() => {
848
- if (property && state.promises.get(first) === actual) state.promises.delete(first);
849
- else if (!property && state.promise === actual) state.promise = void 0;
869
+ if (keyed && state.promises?.get(first) === actual) state.promises?.delete(first);
870
+ else if (!keyed && state.promise === actual) state.promise = void 0;
850
871
  });
851
- } else if (property) setProxyProperty(state, first, actual);
872
+ } else if (keyed) setProxyProperty(state, first, actual);
852
873
  else if (isProxyObject(state.isArray, actual)) setProxyObject(state, actual);
853
874
  }
854
875
  function setValueInProxy(instance, target, property, value) {
@@ -871,60 +892,51 @@ function updateProxyValue(callback) {
871
892
  //#endregion
872
893
  //#region src/value/readonly.ts
873
894
  function Readonly(state, frozen) {
895
+ this[SUBSCRIPTION_TYPE_FROZEN] = frozen;
874
896
  this[SYMBOL_STATE] = state;
875
- Object.defineProperty(this, SUBSCRIPTION_TYPE_FROZEN, {
876
- enumerable: true,
877
- value: frozen
878
- });
879
897
  }
880
898
  Readonly.prototype[NAME_MORA] = NAME_READONLY;
899
+ Readonly.prototype.get = getReadonlyValue;
900
+ Readonly.prototype.peek = peekReadonlyValue;
881
901
  Readonly.prototype.subscribe = subscribeToReadonly;
902
+ Readonly.prototype.toJSON = getJsonValue;
882
903
  Readonly.prototype.toString = getStringValue;
883
- Readonly.prototype.get = function() {
884
- return getReadonlyValue(this, false, this[SUBSCRIPTION_TYPE_FROZEN]);
885
- };
886
- Readonly.prototype.peek = function(copy) {
887
- return getReadonlyValue(this, true, this[SUBSCRIPTION_TYPE_FROZEN], copy);
888
- };
889
- Readonly.prototype.toJSON = function() {
890
- return this[SYMBOL_STATE].value;
891
- };
892
- function getReadonlyInstance(frozen) {
904
+ function getReadonlyInstance(state, frozen) {
905
+ return new Readonly(state, frozen);
906
+ }
907
+ function getReadonlySignal(frozen) {
893
908
  const key = frozen === true ? SUBSCRIPTION_TYPE_FROZEN : SUBSCRIPTION_TYPE_ORIGINAL;
894
909
  this[SYMBOL_STATE].readonlies ??= {};
895
- this[SYMBOL_STATE].readonlies[key] ??= getReadonlySignal(this[SYMBOL_STATE], frozen === true);
910
+ this[SYMBOL_STATE].readonlies[key] ??= getReadonlyInstance(this[SYMBOL_STATE], frozen === true);
896
911
  return this[SYMBOL_STATE].readonlies[key];
897
912
  }
898
- function getReadonlySignal(state, frozen) {
899
- return new Readonly(state, frozen);
913
+ function getReadonlyValue() {
914
+ return handleReadonlyValue(this, false, this[SUBSCRIPTION_TYPE_FROZEN]);
900
915
  }
901
- function getReadonlyValue(instance, peek, frozen, copy) {
916
+ function handleReadonlyValue(instance, peek, frozen, copy) {
902
917
  let value;
903
918
  if (peek) value = peekSignalValue.call(instance, copy === true);
904
919
  else value = getSignalValue.call(instance);
905
920
  return frozen ? getFrozenValue(value) : value;
906
921
  }
922
+ function peekReadonlyValue(copy) {
923
+ return handleReadonlyValue(this, true, this[SUBSCRIPTION_TYPE_FROZEN], copy);
924
+ }
907
925
  //#endregion
908
926
  //#region src/value/signal.ts
909
927
  function Signal(value, options) {
910
928
  this[SYMBOL_STATE] = getState(void 0, options);
911
- handleSignalValue(this, value, setAndEmit);
929
+ handleSignal(this, value, setAndEmit);
912
930
  }
913
931
  Signal.prototype[NAME_MORA] = NAME_SIGNAL;
914
- Signal.prototype.asReadonly = getReadonlyInstance;
932
+ Signal.prototype.asReadonly = getReadonlySignal;
915
933
  Signal.prototype.get = getSignalValue;
916
934
  Signal.prototype.peek = peekSignalValue;
935
+ Signal.prototype.set = setSignalValue;
917
936
  Signal.prototype.subscribe = subscribeToSignal;
918
937
  Signal.prototype.toString = getStringValue;
919
- Signal.prototype.set = function(value) {
920
- return handleSignalValue(this, value, setAndEmit);
921
- };
922
- Signal.prototype.toJSON = function() {
923
- return this[SYMBOL_STATE].value;
924
- };
925
- Signal.prototype.update = function(callback) {
926
- return updateSignalValue(this, callback, setAndEmit);
927
- };
938
+ Signal.prototype.toJSON = getJsonValue;
939
+ Signal.prototype.update = updateSignalValue;
928
940
  function setAndEmit(instance, value) {
929
941
  const state = instance[SYMBOL_STATE];
930
942
  if (!(state.equal ?? Object.is)(state.value, value)) {
@@ -932,9 +944,15 @@ function setAndEmit(instance, value) {
932
944
  emitValue(instance);
933
945
  }
934
946
  }
947
+ function setSignalValue(value) {
948
+ handleSignal(this, value, setAndEmit);
949
+ }
935
950
  function signal(value, options) {
936
951
  return new Signal(value, options);
937
952
  }
953
+ function updateSignalValue(callback) {
954
+ updateSignal(this, callback, setAndEmit);
955
+ }
938
956
  //#endregion
939
957
  //#region src/value/array.ts
940
958
  function ReactiveArray(value, options) {
@@ -947,64 +965,76 @@ function ReactiveArray(value, options) {
947
965
  get: (target, property) => METHODS_UPDATE.has(property) ? updateArray(this, property, target) : Reflect.get(target, property),
948
966
  set: (target, property, value) => setValueInProxy(this, target, property, value)
949
967
  });
950
- Object.defineProperty(this, PROPERTY_LENGTH, {
951
- enumerable: true,
952
- get: () => this[SYMBOL_STATE].length.get(),
953
- set: (value) => setArrayLength(this[SYMBOL_STATE], value)
954
- });
955
968
  setProxyValue.call(this, value);
956
969
  }
957
970
  ReactiveArray.prototype[NAME_MORA] = NAME_ARRAY;
958
- ReactiveArray.prototype.asReadonly = getReadonlyInstance;
971
+ Object.defineProperty(ReactiveArray.prototype, PROPERTY_LENGTH, {
972
+ enumerable: true,
973
+ get: getArrayLength,
974
+ set: setArrayLength
975
+ });
976
+ ReactiveArray.prototype.asReadonly = getReadonlySignal;
959
977
  ReactiveArray.prototype.at = getArrayValues;
978
+ ReactiveArray.prototype.clear = clearArrayValues;
979
+ ReactiveArray.prototype.filter = filterArrayValues;
960
980
  ReactiveArray.prototype.get = getArrayValues;
981
+ ReactiveArray.prototype.map = mapArrayValues;
961
982
  ReactiveArray.prototype.notify = emitProxyValues;
962
983
  ReactiveArray.prototype.peek = peekArrayValue;
984
+ ReactiveArray.prototype.pop = popArrayValue;
985
+ ReactiveArray.prototype.push = pushArrayValues;
986
+ ReactiveArray.prototype.select = selectArrayValues;
987
+ ReactiveArray.prototype.shift = shiftArrayValue;
963
988
  ReactiveArray.prototype.set = setProxyValue;
989
+ ReactiveArray.prototype.splice = spliceArrayValues;
964
990
  ReactiveArray.prototype.subscribe = subscribeToProxy;
965
991
  ReactiveArray.prototype.toString = getStringValue;
992
+ ReactiveArray.prototype.toJSON = getJsonValue;
993
+ ReactiveArray.prototype.unshift = unshiftArrayValues;
966
994
  ReactiveArray.prototype.update = updateProxyValue;
967
- ReactiveArray.prototype.clear = function() {
968
- this[SYMBOL_STATE].value.length = 0;
969
- };
970
- ReactiveArray.prototype.filter = function(callback) {
971
- return computed(() => filter(getArrayValues.call(this), callback));
972
- };
973
- ReactiveArray.prototype.map = function(callback) {
974
- return computed(() => getArrayValues.call(this).map(callback));
975
- };
976
- ReactiveArray.prototype.pop = function() {
977
- return this[SYMBOL_STATE].value.pop();
978
- };
979
- ReactiveArray.prototype.push = function(...items) {
980
- return this[SYMBOL_STATE].value.push(...items);
981
- };
982
- ReactiveArray.prototype.select = function(filter, map) {
983
- return computed(() => select(getArrayValues.call(this), filter, map));
984
- };
985
- ReactiveArray.prototype.shift = function() {
986
- return this[SYMBOL_STATE].value.shift();
987
- };
988
- ReactiveArray.prototype.splice = function(from, to, ...items) {
989
- return this[SYMBOL_STATE].value.splice(from, to ?? this[SYMBOL_STATE].value.length, ...items);
990
- };
991
- ReactiveArray.prototype.toJSON = function() {
992
- return this[SYMBOL_STATE].value;
993
- };
994
- ReactiveArray.prototype.unshift = function(...items) {
995
- return this[SYMBOL_STATE].value.unshift(...items);
996
- };
997
995
  function array(value, options) {
998
996
  return new ReactiveArray(value, options);
999
997
  }
998
+ function clearArrayValues() {
999
+ this[SYMBOL_STATE].value.length = 0;
1000
+ }
1001
+ function filterArrayValues(callback) {
1002
+ return computed(() => filter(getArrayValues.call(this), callback));
1003
+ }
1004
+ function getArrayLength() {
1005
+ return this[SYMBOL_STATE].length.get();
1006
+ }
1000
1007
  function getArrayValues(value) {
1001
1008
  return value === "length" ? this[SYMBOL_STATE].length.get() : getValueInProxy.call(this, value);
1002
1009
  }
1010
+ function mapArrayValues(callback) {
1011
+ return computed(() => getArrayValues.call(this).map(callback));
1012
+ }
1003
1013
  function peekArrayValue(first, second) {
1004
1014
  return first === "length" ? this[SYMBOL_STATE].length.peek() : peekValueInProxy.call(this, first, second);
1005
1015
  }
1006
- function setArrayLength(state, value) {
1007
- if (typeof value === "number" && !Number.isNaN(value) && value >= 0 && value !== state.value.length) state.value.length = value;
1016
+ function popArrayValue() {
1017
+ return this[SYMBOL_STATE].value.pop();
1018
+ }
1019
+ function pushArrayValues(...items) {
1020
+ return this[SYMBOL_STATE].value.push(...items);
1021
+ }
1022
+ function selectArrayValues(filter, map) {
1023
+ return computed(() => select(getArrayValues.call(this), filter, map));
1024
+ }
1025
+ function setArrayLength(value) {
1026
+ const values = this[SYMBOL_STATE].value;
1027
+ if (typeof value === "number" && !Number.isNaN(value) && value >= 0 && value !== values.length) values.length = value;
1028
+ }
1029
+ function shiftArrayValue() {
1030
+ return this[SYMBOL_STATE].value.shift();
1031
+ }
1032
+ function spliceArrayValues(from, to, ...items) {
1033
+ const values = this[SYMBOL_STATE].value;
1034
+ return values.splice(from, to ?? values.length, ...items);
1035
+ }
1036
+ function unshiftArrayValues(...items) {
1037
+ return this[SYMBOL_STATE].value.unshift(...items);
1008
1038
  }
1009
1039
  function updateArray(instance, type, array) {
1010
1040
  const state = instance[SYMBOL_STATE];
@@ -1013,7 +1043,7 @@ function updateArray(instance, type, array) {
1013
1043
  const previousLength = array.length;
1014
1044
  return (...args) => {
1015
1045
  const result = array[type](...args);
1016
- if (affectsLength ? array.length !== previousLength : !equalArrays(state, previousArray, array)) {
1046
+ if (affectsLength ? array.length !== previousLength : !equalArrays(previousArray, array, state.equal)) {
1017
1047
  emitValue(instance);
1018
1048
  state.length.set(array.length);
1019
1049
  }
@@ -1031,17 +1061,15 @@ function ReactiveStore(value, options) {
1031
1061
  setProxyValue.call(this, value);
1032
1062
  }
1033
1063
  ReactiveStore.prototype[NAME_MORA] = NAME_STORE;
1034
- ReactiveStore.prototype.asReadonly = getReadonlyInstance;
1064
+ ReactiveStore.prototype.asReadonly = getReadonlySignal;
1035
1065
  ReactiveStore.prototype.get = getValueInProxy;
1036
1066
  ReactiveStore.prototype.notify = emitProxyValues;
1037
1067
  ReactiveStore.prototype.peek = peekValueInProxy;
1038
1068
  ReactiveStore.prototype.set = setProxyValue;
1039
1069
  ReactiveStore.prototype.subscribe = subscribeToProxy;
1070
+ ReactiveStore.prototype.toJSON = getJsonValue;
1040
1071
  ReactiveStore.prototype.toString = getStringValue;
1041
1072
  ReactiveStore.prototype.update = updateProxyValue;
1042
- ReactiveStore.prototype.toJSON = function() {
1043
- return this[SYMBOL_STATE].value;
1044
- };
1045
1073
  function store(value, options) {
1046
1074
  return new ReactiveStore(value, options);
1047
1075
  }