aoye 0.0.7 → 0.0.8

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/aoye.cjs.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var bobeShared = require('bobe-shared');
4
4
 
5
+ const rawToProxy = /* @__PURE__ */ new WeakMap();
5
6
  new bobeShared.BaseEvent();
6
7
  const G = {
7
8
  /** 原子 signal 更新次数 */
@@ -13,7 +14,6 @@ const G = {
13
14
  /** 表示当前处于 pull 递归中 */
14
15
  PullingRecurseDeep: 0
15
16
  };
16
- new bobeShared.SortMap();
17
17
  var State = /* @__PURE__ */ ((State2) => {
18
18
  State2[State2["Clean"] = 0] = "Clean";
19
19
  State2[State2["LinkScopeOnly"] = 256] = "LinkScopeOnly";
@@ -134,19 +134,19 @@ class PriorityQueue {
134
134
  }
135
135
  }
136
136
 
137
- var __defProp$2 = Object.defineProperty;
138
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
139
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
140
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
141
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
142
- var __spreadValues$2 = (a, b) => {
137
+ var __defProp$3 = Object.defineProperty;
138
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
139
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
140
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
141
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
142
+ var __spreadValues$3 = (a, b) => {
143
143
  for (var prop in b || (b = {}))
144
- if (__hasOwnProp$3.call(b, prop))
145
- __defNormalProp$2(a, prop, b[prop]);
146
- if (__getOwnPropSymbols$3)
147
- for (var prop of __getOwnPropSymbols$3(b)) {
148
- if (__propIsEnum$3.call(b, prop))
149
- __defNormalProp$2(a, prop, b[prop]);
144
+ if (__hasOwnProp$4.call(b, prop))
145
+ __defNormalProp$3(a, prop, b[prop]);
146
+ if (__getOwnPropSymbols$4)
147
+ for (var prop of __getOwnPropSymbols$4(b)) {
148
+ if (__propIsEnum$4.call(b, prop))
149
+ __defNormalProp$3(a, prop, b[prop]);
150
150
  }
151
151
  return a;
152
152
  };
@@ -178,7 +178,7 @@ class TaskQueue {
178
178
  const fn = taskQueue.peek();
179
179
  if (!fn) return this.isScheduling = false;
180
180
  let info = fn() || {};
181
- info = __spreadValues$2(__spreadValues$2({}, DefaultTaskControlReturn), info);
181
+ info = __spreadValues$3(__spreadValues$3({}, DefaultTaskControlReturn), info);
182
182
  if (info.finished) {
183
183
  taskQueue.poll();
184
184
  if (taskQueue.size() === 0) {
@@ -193,6 +193,14 @@ class TaskQueue {
193
193
  }
194
194
  }
195
195
 
196
+ var Keys = /* @__PURE__ */ ((Keys2) => {
197
+ Keys2["Iterator"] = "__AOYE_ITERATOR";
198
+ Keys2["Raw"] = "__AOYE_RAW";
199
+ Keys2["Deep"] = "__AOYE_DEEP";
200
+ Keys2["Scope"] = "__AOYE_SCOPE";
201
+ return Keys2;
202
+ })(Keys || {});
203
+
196
204
  let channel = globalThis.MessageChannel ? new MessageChannel() : null;
197
205
  if (globalThis.MessageChannel) {
198
206
  channel = new MessageChannel();
@@ -216,10 +224,28 @@ const p = Promise.resolve();
216
224
  const micro = (cb) => {
217
225
  p.then(cb);
218
226
  };
227
+ const toRaw = (a) => {
228
+ if (typeof a === "object" && a !== null && a[Keys.Raw]) {
229
+ return toRaw(a[Keys.Raw]);
230
+ }
231
+ return a;
232
+ };
219
233
 
220
234
  class Scheduler {
221
235
  constructor() {
222
236
  this.effectQueue = new bobeShared.Queue();
237
+ /** 每当 Set 或 BatchSet 开始时标记 */
238
+ this.firstEffectItem = null;
239
+ /** 记录 Set 或 BatchSet 产生的最后一个 Effect */
240
+ this.lastEffectItem = null;
241
+ }
242
+ endSet() {
243
+ var _a;
244
+ if (!this.firstEffectItem) return;
245
+ const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
246
+ (_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
247
+ this.firstEffectItem = null;
248
+ this.lastEffectItem = null;
223
249
  }
224
250
  addEffect(effect) {
225
251
  var _a;
@@ -300,19 +326,19 @@ const _scheduler = {
300
326
  };
301
327
  const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
302
328
 
303
- var __defProp$1 = Object.defineProperty;
304
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
305
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
306
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
307
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
308
- var __spreadValues$1 = (a, b) => {
329
+ var __defProp$2 = Object.defineProperty;
330
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
331
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
332
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
333
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
334
+ var __spreadValues$2 = (a, b) => {
309
335
  for (var prop in b || (b = {}))
310
- if (__hasOwnProp$2.call(b, prop))
311
- __defNormalProp$1(a, prop, b[prop]);
312
- if (__getOwnPropSymbols$2)
313
- for (var prop of __getOwnPropSymbols$2(b)) {
314
- if (__propIsEnum$2.call(b, prop))
315
- __defNormalProp$1(a, prop, b[prop]);
336
+ if (__hasOwnProp$3.call(b, prop))
337
+ __defNormalProp$2(a, prop, b[prop]);
338
+ if (__getOwnPropSymbols$3)
339
+ for (var prop of __getOwnPropSymbols$3(b)) {
340
+ if (__propIsEnum$3.call(b, prop))
341
+ __defNormalProp$2(a, prop, b[prop]);
316
342
  }
317
343
  return a;
318
344
  };
@@ -325,7 +351,7 @@ const DefaultDFSOpt = {
325
351
  breakNode: null
326
352
  };
327
353
  function dfs(root, opt = {}) {
328
- const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$1(__spreadValues$1({}, DefaultDFSOpt), opt);
354
+ const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$2(__spreadValues$2({}, DefaultDFSOpt), opt);
329
355
  let node = opt.breakNode || root;
330
356
  let line = breakLine;
331
357
  const listKey = isUp ? "recStart" : "emitStart";
@@ -611,27 +637,49 @@ function clean(cb) {
611
637
  function runWithPulling(fn, signal) {
612
638
  const prevPulling = G.PullingSignal;
613
639
  G.PullingSignal = signal;
614
- fn();
640
+ const res = fn();
615
641
  G.PullingSignal = prevPulling;
642
+ return res;
616
643
  }
617
644
 
618
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
619
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
620
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
645
+ class Batch {
646
+ constructor() {
647
+ this.deep = 0;
648
+ }
649
+ start() {
650
+ this.deep++;
651
+ }
652
+ end() {
653
+ this.deep--;
654
+ if (this.deep !== 0) return;
655
+ for (const key in _scheduler) {
656
+ const instance = _scheduler[key];
657
+ instance.endSet();
658
+ }
659
+ }
660
+ inBatch() {
661
+ return this.deep > 0;
662
+ }
663
+ }
664
+ const batch = new Batch();
665
+
666
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
667
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
668
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
621
669
  var __objRest = (source, exclude) => {
622
670
  var target = {};
623
671
  for (var prop in source)
624
- if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
672
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
625
673
  target[prop] = source[prop];
626
- if (source != null && __getOwnPropSymbols$1)
627
- for (var prop of __getOwnPropSymbols$1(source)) {
628
- if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
674
+ if (source != null && __getOwnPropSymbols$2)
675
+ for (var prop of __getOwnPropSymbols$2(source)) {
676
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
629
677
  target[prop] = source[prop];
630
678
  }
631
679
  return target;
632
680
  };
633
681
  const markDeep = (signal) => {
634
- let level = 0, firstEffectItem, lastEffectItem, updatedSchedulers = /* @__PURE__ */ new Set();
682
+ let level = 0, updatedSchedulers = /* @__PURE__ */ new Set();
635
683
  dfs(signal, {
636
684
  isUp: false,
637
685
  begin: ({ node }) => {
@@ -651,18 +699,19 @@ const markDeep = (signal) => {
651
699
  const key = node.scheduler;
652
700
  const instance = _scheduler[key];
653
701
  const item = instance.addEffect(node);
654
- if (!firstEffectItem) {
655
- firstEffectItem = item;
702
+ if (!instance.firstEffectItem) {
703
+ instance.firstEffectItem = item;
656
704
  }
657
- lastEffectItem = item;
705
+ instance.lastEffectItem = item;
658
706
  updatedSchedulers.add(key);
659
707
  }
660
708
  level++;
661
709
  }
662
710
  });
663
- for (const key of updatedSchedulers) {
711
+ if (batch.inBatch()) return;
712
+ for (const key in _scheduler) {
664
713
  const instance = _scheduler[key];
665
- instance == null ? void 0 : instance.onOneSetEffectsAdded(instance.effectQueue.subRef(firstEffectItem, lastEffectItem), instance.effectQueue);
714
+ instance.endSet();
666
715
  }
667
716
  };
668
717
  const pullingPostprocess = (node) => {
@@ -693,13 +742,16 @@ const _Signal = class _Signal {
693
742
  this.clean = null;
694
743
  }
695
744
  static create(nextValue, _a) {
696
- var _b = _a, { customPull, isScope, immediate } = _b, rest = __objRest(_b, ["customPull", "isScope", "immediate"]);
745
+ var _b = _a, { customPull, isScope, scope, immediate } = _b, rest = __objRest(_b, ["customPull", "isScope", "scope", "immediate"]);
697
746
  const s = new _Signal(nextValue, customPull);
698
747
  s.pull = s.customPull || s.DEFAULT_PULL;
699
748
  Object.assign(s, rest);
700
749
  if (isScope) {
701
750
  s.state |= State.IsScope;
702
751
  }
752
+ if (scope !== void 0) {
753
+ s.scope = scope;
754
+ }
703
755
  return s;
704
756
  }
705
757
  DEFAULT_PULL() {
@@ -844,41 +896,74 @@ const _Signal = class _Signal {
844
896
  _Signal.Pulling = null;
845
897
  let Signal = _Signal;
846
898
 
847
- var Keys = /* @__PURE__ */ ((Keys2) => {
848
- Keys2["Iterator"] = "__Aoye_Iterator";
849
- Keys2["Raw"] = "__Aoye_Raw";
850
- return Keys2;
851
- })(Keys || {});
852
-
853
- const proxyMap = /* @__PURE__ */ new WeakMap();
854
- const deepSignal = (target, deep = true) => {
899
+ var __defProp$1 = Object.defineProperty;
900
+ var __defProps = Object.defineProperties;
901
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
902
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
903
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
904
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
905
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
906
+ var __spreadValues$1 = (a, b) => {
907
+ for (var prop in b || (b = {}))
908
+ if (__hasOwnProp$1.call(b, prop))
909
+ __defNormalProp$1(a, prop, b[prop]);
910
+ if (__getOwnPropSymbols$1)
911
+ for (var prop of __getOwnPropSymbols$1(b)) {
912
+ if (__propIsEnum$1.call(b, prop))
913
+ __defNormalProp$1(a, prop, b[prop]);
914
+ }
915
+ return a;
916
+ };
917
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
918
+ const deepSignal = (target, scope, deep = true) => {
855
919
  const isObj = typeof target === "object" && target !== null;
856
- if (!isObj) return target;
857
- if (proxyMap.has(target)) return proxyMap.get(target);
920
+ if (!isObj || target[Keys.Raw]) return target;
921
+ if (rawToProxy.has(target)) return rawToProxy.get(target);
858
922
  const cells = /* @__PURE__ */ new Map();
923
+ const targetIsArray = Array.isArray(target);
859
924
  const proxy = new Proxy(target, {
860
925
  get(obj, prop, receiver) {
861
- if (prop === Keys.Raw) {
862
- return target;
926
+ switch (prop) {
927
+ case Keys.Raw:
928
+ return target;
929
+ case Keys.Deep:
930
+ return deep;
931
+ case Keys.Scope:
932
+ return scope;
933
+ }
934
+ const value = Reflect.get(obj, prop, receiver);
935
+ const valueIsFn = typeof value === "function";
936
+ if (valueIsFn) {
937
+ if (targetIsArray) {
938
+ return arrayMethodReWrites[prop] || value;
939
+ } else {
940
+ return value;
941
+ }
863
942
  }
864
943
  if (cells.has(prop)) {
865
944
  return cells.get(prop).v;
866
945
  }
867
- const value = Reflect.get(obj, prop, receiver);
868
- const wrappedValue = deep ? deepSignal(value) : value;
946
+ const wrappedValue = deep ? deepSignal(value, scope) : value;
869
947
  const s = Signal.create(wrappedValue, {
870
948
  scheduler: Scheduler.Sync,
871
- isScope: false
949
+ isScope: false,
950
+ scope
872
951
  });
873
952
  cells.set(prop, s);
874
953
  return s.v;
875
954
  },
876
955
  set(obj, prop, value, receiver) {
956
+ batch.start();
957
+ const success = Reflect.set(obj, prop, value, receiver);
877
958
  if (cells.has(prop)) {
878
959
  const cell = cells.get(prop);
879
- cell.v = deep ? deepSignal(value) : value;
960
+ cell.v = deep ? deepSignal(value, scope) : value;
961
+ }
962
+ if (targetIsArray) {
963
+ handleArraySet(obj, prop, value, receiver);
880
964
  }
881
- return Reflect.set(obj, prop, value, receiver);
965
+ batch.end();
966
+ return success;
882
967
  },
883
968
  // 【核心修改】拦截 delete 操作
884
969
  deleteProperty(obj, prop) {
@@ -886,11 +971,320 @@ const deepSignal = (target, deep = true) => {
886
971
  cells.delete(prop);
887
972
  }
888
973
  return Reflect.deleteProperty(obj, prop);
974
+ },
975
+ ownKeys(obj) {
976
+ if (targetIsArray) {
977
+ proxy.length;
978
+ } else {
979
+ proxy[Keys.Iterator];
980
+ }
981
+ return Reflect.ownKeys(obj);
889
982
  }
890
983
  });
891
- proxyMap.set(target, proxy);
984
+ rawToProxy.set(target, proxy);
892
985
  return proxy;
893
986
  };
987
+ function handleArraySet(arr, prop, value, receiver) {
988
+ if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
989
+ receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
990
+ } else ;
991
+ }
992
+ const arrayMethodReWrites = {};
993
+ ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
994
+ arrayMethodReWrites[key] = function(...args) {
995
+ batch.start();
996
+ const fn = Array.prototype[key];
997
+ const res = runWithPulling(() => fn.call(this, ...args), null);
998
+ this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
999
+ batch.end();
1000
+ return res;
1001
+ };
1002
+ });
1003
+ ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
1004
+ arrayMethodReWrites[key] = function(...args) {
1005
+ const fn = Array.prototype[key];
1006
+ const that = toRaw(this);
1007
+ let result = fn.call(that, ...args);
1008
+ const value = args[0];
1009
+ if ((result === false || result === -1) && typeof value === "object" && value !== null) {
1010
+ if (value[Keys.Raw]) {
1011
+ args[0] = value[Keys.Raw];
1012
+ result = fn.call(that, ...args);
1013
+ }
1014
+ if (rawToProxy.has(value)) {
1015
+ args[0] = rawToProxy.get(value);
1016
+ result = fn.call(that, ...args);
1017
+ }
1018
+ }
1019
+ this[Keys.Iterator];
1020
+ return result;
1021
+ };
1022
+ });
1023
+ [Symbol.iterator, "values", "entries"].forEach((key) => {
1024
+ const isEntries = key === "entries";
1025
+ arrayMethodReWrites[key] = function(...args) {
1026
+ const fn = Array.prototype[key];
1027
+ const rawArray = toRaw(this);
1028
+ const iter = fn.call(rawArray, ...args);
1029
+ const scope = this[Keys.Scope];
1030
+ const isDeep = this[Keys.Deep];
1031
+ if (isDeep) {
1032
+ const rawNext = iter.next.bind(iter);
1033
+ iter.next = () => {
1034
+ const result = rawNext();
1035
+ if (!result.done) {
1036
+ if (isEntries) {
1037
+ result.value[1] = deepSignal(result.value[1], scope);
1038
+ } else {
1039
+ result.value = deepSignal(result.value, scope);
1040
+ }
1041
+ }
1042
+ return result;
1043
+ };
1044
+ }
1045
+ this[Keys.Iterator];
1046
+ return iter;
1047
+ };
1048
+ });
1049
+ arrayMethodReWrites.filter = function(callback, thisArg) {
1050
+ const scope = this[Keys.Scope];
1051
+ const isDeep = this[Keys.Deep];
1052
+ const that = toRaw(this);
1053
+ const result = [];
1054
+ let resultIndex = 0;
1055
+ const userThis = thisArg || that;
1056
+ const len = that.length;
1057
+ for (let i = 0; i < len; i++) {
1058
+ if (i in that) {
1059
+ const value = isDeep ? deepSignal(that[i], scope) : that[i];
1060
+ if (callback.call(userThis, value, i, userThis)) {
1061
+ result[resultIndex++] = value;
1062
+ }
1063
+ }
1064
+ }
1065
+ this[Keys.Iterator];
1066
+ return result;
1067
+ };
1068
+ arrayMethodReWrites.slice = function(start, end) {
1069
+ const scope = this[Keys.Scope];
1070
+ const isDeep = this[Keys.Deep];
1071
+ const that = toRaw(this);
1072
+ const len = that.length;
1073
+ let k = start || 0;
1074
+ if (k < 0) {
1075
+ k = Math.max(len + k, 0);
1076
+ } else {
1077
+ k = Math.min(k, len);
1078
+ }
1079
+ let final = end === void 0 ? len : end;
1080
+ if (final < 0) {
1081
+ final = Math.max(len + final, 0);
1082
+ } else {
1083
+ final = Math.min(final, len);
1084
+ }
1085
+ const count = Math.max(final - k, 0);
1086
+ const result = new Array(count);
1087
+ for (let i = 0; i < count; i++) {
1088
+ if (i + k in that) {
1089
+ result[i] = isDeep ? deepSignal(that[i + k], scope) : that[i + k];
1090
+ }
1091
+ }
1092
+ this[Keys.Iterator];
1093
+ return result;
1094
+ };
1095
+ arrayMethodReWrites.toReversed = function() {
1096
+ const scope = this[Keys.Scope];
1097
+ const isDeep = this[Keys.Deep];
1098
+ const that = toRaw(this);
1099
+ const len = that.length;
1100
+ const result = new Array(len);
1101
+ let k = 0;
1102
+ while (k < len) {
1103
+ result[k] = isDeep ? deepSignal(that[len - 1 - k], scope) : that[len - 1 - k];
1104
+ k++;
1105
+ }
1106
+ this[Keys.Iterator];
1107
+ return result;
1108
+ };
1109
+ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1110
+ const scope = this[Keys.Scope];
1111
+ const isDeep = this[Keys.Deep];
1112
+ const that = toRaw(this);
1113
+ const len = that.length;
1114
+ let relativeStart = start >> 0;
1115
+ let actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
1116
+ let actualDeleteCount;
1117
+ if (arguments.length === 0) {
1118
+ actualDeleteCount = 0;
1119
+ } else if (arguments.length === 1) {
1120
+ actualDeleteCount = len - actualStart;
1121
+ } else {
1122
+ let dc = deleteCount >> 0;
1123
+ actualDeleteCount = Math.min(Math.max(dc, 0), len - actualStart);
1124
+ }
1125
+ const insertCount = items.length;
1126
+ const newLen = len - actualDeleteCount + insertCount;
1127
+ const result = new Array(newLen);
1128
+ for (let i = 0; i < actualStart; i++) {
1129
+ result[i] = isDeep ? deepSignal(that[i], scope) : that[i];
1130
+ }
1131
+ for (let i = 0; i < insertCount; i++) {
1132
+ result[actualStart + i] = isDeep ? deepSignal(items[i], scope) : items[i];
1133
+ }
1134
+ const remainingStart = actualStart + actualDeleteCount;
1135
+ const resultOffset = actualStart + insertCount;
1136
+ for (let i = 0; i < len - remainingStart; i++) {
1137
+ result[resultOffset + i] = isDeep ? deepSignal(that[remainingStart + i], scope) : that[remainingStart + i];
1138
+ }
1139
+ this[Keys.Iterator];
1140
+ return result;
1141
+ };
1142
+ arrayMethodReWrites.with = function(index, value) {
1143
+ const scope = this[Keys.Scope];
1144
+ const isDeep = this[Keys.Deep];
1145
+ const that = toRaw(this);
1146
+ const len = that.length;
1147
+ let relativeIndex = Number(index) || 0;
1148
+ let actualIndex = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
1149
+ if (actualIndex >= len || actualIndex < 0) {
1150
+ throw new RangeError(`Invalid index: ${index}`);
1151
+ }
1152
+ const result = new Array(len);
1153
+ for (let i = 0; i < len; i++) {
1154
+ if (i === actualIndex) {
1155
+ result[i] = isDeep ? deepSignal(value, scope) : value;
1156
+ } else {
1157
+ result[i] = isDeep ? deepSignal(that[i], scope) : that[i];
1158
+ }
1159
+ }
1160
+ this[Keys.Iterator];
1161
+ return result;
1162
+ };
1163
+ arrayMethodReWrites.concat = function(...items) {
1164
+ const scope = this[Keys.Scope];
1165
+ const isDeep = this[Keys.Deep];
1166
+ const that = toRaw(this);
1167
+ const selfLen = that.length;
1168
+ let totalLength = selfLen;
1169
+ for (let i = 0; i < items.length; i++) {
1170
+ const item = items[i];
1171
+ if (Array.isArray(item)) {
1172
+ totalLength += item.length;
1173
+ } else {
1174
+ totalLength += 1;
1175
+ }
1176
+ }
1177
+ const result = new Array(totalLength);
1178
+ let k = 0;
1179
+ for (; k < selfLen; k++) {
1180
+ if (k in that) {
1181
+ result[k] = isDeep ? deepSignal(that[k], scope) : that[k];
1182
+ }
1183
+ }
1184
+ for (let i = 0; i < items.length; i++) {
1185
+ const item = items[i];
1186
+ if (Array.isArray(item)) {
1187
+ for (let j = 0; j < item.length; j++) {
1188
+ if (j in item) {
1189
+ result[k] = isDeep ? deepSignal(item[j], scope) : item[j];
1190
+ }
1191
+ k++;
1192
+ }
1193
+ } else {
1194
+ result[k] = isDeep ? deepSignal(item, scope) : item;
1195
+ k++;
1196
+ }
1197
+ }
1198
+ this[Keys.Iterator];
1199
+ return result;
1200
+ };
1201
+ const GetMethodConf = {
1202
+ wrapReturn: false,
1203
+ wrapArgs: 1
1204
+ };
1205
+ [
1206
+ __spreadValues$1({
1207
+ key: "every"
1208
+ }, GetMethodConf),
1209
+ __spreadValues$1({
1210
+ key: "find",
1211
+ wrapReturn: true
1212
+ }, GetMethodConf),
1213
+ __spreadProps(__spreadValues$1({
1214
+ key: "findLast"
1215
+ }, GetMethodConf), {
1216
+ wrapReturn: true
1217
+ }),
1218
+ __spreadValues$1({
1219
+ key: "findIndex"
1220
+ }, GetMethodConf),
1221
+ __spreadValues$1({
1222
+ key: "findLastIndex"
1223
+ }, GetMethodConf),
1224
+ __spreadValues$1({
1225
+ key: "forEach"
1226
+ }, GetMethodConf),
1227
+ __spreadValues$1({
1228
+ key: "map"
1229
+ }, GetMethodConf),
1230
+ __spreadValues$1({
1231
+ key: "some"
1232
+ }, GetMethodConf),
1233
+ __spreadProps(__spreadValues$1({
1234
+ key: "reduce"
1235
+ }, GetMethodConf), {
1236
+ wrapArgs: 2
1237
+ }),
1238
+ __spreadProps(__spreadValues$1({
1239
+ key: "reduceRight"
1240
+ }, GetMethodConf), {
1241
+ wrapArgs: 2
1242
+ })
1243
+ ].forEach(({ key, wrapReturn, wrapArgs }) => {
1244
+ arrayMethodReWrites[key] = function(...args) {
1245
+ const scope = this[Keys.Scope];
1246
+ const fn = Array.prototype[key];
1247
+ const isDeep = this[Keys.Deep];
1248
+ const that = toRaw(this);
1249
+ warpCallbackArgs(isDeep, args, scope, wrapArgs);
1250
+ let result = fn.call(that, ...args);
1251
+ if (wrapReturn && isDeep) {
1252
+ result = deepSignal(result, scope);
1253
+ }
1254
+ this[Keys.Iterator];
1255
+ return result;
1256
+ };
1257
+ });
1258
+ arrayMethodReWrites.toSorted = function(...args) {
1259
+ const fn = Array.prototype["toSorted"];
1260
+ const scope = this[Keys.Scope];
1261
+ const isDeep = this[Keys.Deep];
1262
+ const that = toRaw(this);
1263
+ warpCallbackArgs(isDeep, args, scope, 3);
1264
+ let result = fn.call(that, ...args);
1265
+ this[Keys.Iterator];
1266
+ return isDeep ? result.map((it) => deepSignal(it, scope)) : result;
1267
+ };
1268
+ ["join", "toString", "toLocaleString"].forEach((key) => {
1269
+ arrayMethodReWrites[key] = function(...args) {
1270
+ const fn = Array.prototype[key];
1271
+ const that = toRaw(this);
1272
+ const result = fn.call(that, ...args);
1273
+ this[Keys.Iterator];
1274
+ return result;
1275
+ };
1276
+ });
1277
+ function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
1278
+ const callback = args[0];
1279
+ const wrapCb = function(...cbArgs) {
1280
+ if (isDeep) {
1281
+ if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
1282
+ if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
1283
+ }
1284
+ return callback.call(this, ...cbArgs);
1285
+ };
1286
+ args[0] = wrapCb;
1287
+ }
894
1288
 
895
1289
  var __defProp = Object.defineProperty;
896
1290
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -927,7 +1321,7 @@ const $ = (init, opt = {}) => {
927
1321
  intiValue = null;
928
1322
  customPull = init;
929
1323
  } else if (opt.mode !== "ref" && typeof init === "object" && init !== null) {
930
- return deepSignal(init, opt.deep);
1324
+ return deepSignal(init, G.PullingSignal, opt.deep);
931
1325
  } else {
932
1326
  intiValue = init;
933
1327
  }
@@ -1007,6 +1401,7 @@ exports.$ = $;
1007
1401
  exports.Keys = Keys;
1008
1402
  exports.Scheduler = Scheduler;
1009
1403
  exports.TaskQueue = TaskQueue;
1404
+ exports.batch = batch;
1010
1405
  exports.clean = clean;
1011
1406
  exports.customEffect = customEffect;
1012
1407
  exports.effect = effect;