@lytjs/reactivity 6.9.0 → 6.9.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.cjs CHANGED
@@ -672,12 +672,45 @@ var arrayInstrumentations = {};
672
672
  return result;
673
673
  };
674
674
  });
675
+ var arrayTraverseMethods = [
676
+ "join",
677
+ "map",
678
+ "filter",
679
+ "reduce",
680
+ "reduceRight",
681
+ "forEach",
682
+ "some",
683
+ "every",
684
+ "flat",
685
+ "flatMap",
686
+ "keys",
687
+ "values",
688
+ "entries",
689
+ "toReversed",
690
+ "toSorted",
691
+ "toSpliced",
692
+ "with"
693
+ ];
694
+ arrayTraverseMethods.forEach((method) => {
695
+ if (Array.prototype[method]) {
696
+ const originMethod = Array.prototype[method];
697
+ arrayInstrumentations[method] = function(...args) {
698
+ const arr = toRaw(this);
699
+ track(arr, TrackOpTypes.ITERATE, ITERATE_KEY);
700
+ track(arr, TrackOpTypes.GET, "length");
701
+ const result = originMethod.apply(this, args);
702
+ return result;
703
+ };
704
+ }
705
+ });
675
706
  ["push", "pop", "shift", "unshift", "splice"].forEach((method) => {
676
707
  const originMethod = Array.prototype[method];
677
708
  arrayInstrumentations[method] = function(...args) {
709
+ const arr = toRaw(this);
678
710
  pauseTracking();
679
711
  try {
680
- const result = originMethod.apply(this, args);
712
+ const result = originMethod.apply(arr, args);
713
+ trigger(arr, TriggerOpTypes.ADD, ITERATE_KEY);
681
714
  return result;
682
715
  } finally {
683
716
  resetTracking();
@@ -691,13 +724,24 @@ var arrayInstrumentations = {};
691
724
  pauseTracking();
692
725
  try {
693
726
  const result = originMethod.apply(arr, args);
694
- trigger(arr, TriggerOpTypes.SET, "length");
727
+ trigger(arr, TriggerOpTypes.ADD, ITERATE_KEY);
695
728
  return result;
696
729
  } finally {
697
730
  resetTracking();
698
731
  }
699
732
  };
700
733
  });
734
+ var skipMethods = /* @__PURE__ */ new Set(["constructor", "toString", "toLocaleString", "valueOf", "Symbol(Symbol.iterator)"]);
735
+ var arrayMethods = Object.getOwnPropertyNames(Array.prototype);
736
+ arrayMethods.forEach((method) => {
737
+ if (!arrayInstrumentations[method] && !skipMethods.has(method) && typeof Array.prototype[method] === "function") {
738
+ const originMethod = Array.prototype[method];
739
+ arrayInstrumentations[method] = function(...args) {
740
+ const arr = toRaw(this);
741
+ return originMethod.apply(arr, args);
742
+ };
743
+ }
744
+ });
701
745
  var builtInSymbols = new Set(
702
746
  Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => {
703
747
  const value = commonAssertions.unsafeCast(Symbol[key]);
@@ -739,6 +783,7 @@ function createMutableHandler(isReadonly2, isShallow) {
739
783
  if (key === ReactiveFlags.IS_READONLY) return isReadonly2;
740
784
  if (key === ReactiveFlags.IS_SHALLOW) return isShallow;
741
785
  if (key === ReactiveFlags.RAW) return target;
786
+ if (key === "prototype") return Reflect.get(target, key, target);
742
787
  const targetIsArray = Array.isArray(target);
743
788
  if (!isReadonly2 && targetIsArray && commonIs.hasOwn(arrayInstrumentations, key)) {
744
789
  return Reflect.get(arrayInstrumentations, key, _receiver);
@@ -813,6 +858,12 @@ function createMutableHandler(isReadonly2, isShallow) {
813
858
  track(target, TrackOpTypes.ITERATE, Array.isArray(target) ? "length" : ITERATE_KEY);
814
859
  }
815
860
  return Reflect.ownKeys(target);
861
+ },
862
+ getPrototypeOf(target) {
863
+ return Reflect.getPrototypeOf(target);
864
+ },
865
+ setPrototypeOf(target, proto) {
866
+ return Reflect.setPrototypeOf(target, proto);
816
867
  }
817
868
  };
818
869
  }