@lytjs/reactivity 6.9.0 → 6.9.1

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