aoye 0.0.7 → 0.0.9

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,16 @@ 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
+ Keys2["Cells"] = "__AOYE_CELLS";
202
+ return Keys2;
203
+ })(Keys || {});
204
+ const IsStore = /* @__PURE__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
205
+
196
206
  let channel = globalThis.MessageChannel ? new MessageChannel() : null;
197
207
  if (globalThis.MessageChannel) {
198
208
  channel = new MessageChannel();
@@ -216,10 +226,28 @@ const p = Promise.resolve();
216
226
  const micro = (cb) => {
217
227
  p.then(cb);
218
228
  };
229
+ const toRaw = (a) => {
230
+ if (typeof a === "object" && a !== null && a[Keys.Raw]) {
231
+ return toRaw(a[Keys.Raw]);
232
+ }
233
+ return a;
234
+ };
219
235
 
220
236
  class Scheduler {
221
237
  constructor() {
222
238
  this.effectQueue = new bobeShared.Queue();
239
+ /** 每当 Set 或 BatchSet 开始时标记 */
240
+ this.firstEffectItem = null;
241
+ /** 记录 Set 或 BatchSet 产生的最后一个 Effect */
242
+ this.lastEffectItem = null;
243
+ }
244
+ endSet() {
245
+ var _a;
246
+ if (!this.firstEffectItem) return;
247
+ const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
248
+ (_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
249
+ this.firstEffectItem = null;
250
+ this.lastEffectItem = null;
223
251
  }
224
252
  addEffect(effect) {
225
253
  var _a;
@@ -236,7 +264,7 @@ class SyncScheduler extends Scheduler {
236
264
  onOneSetEffectsAdded(subQueue, queue) {
237
265
  subQueue.forEach((effect, item) => {
238
266
  effect.runIfDirty();
239
- subQueue.delete(item);
267
+ queue.delete(item);
240
268
  });
241
269
  }
242
270
  }
@@ -249,7 +277,7 @@ class MicroScheduler extends Scheduler {
249
277
  const task = () => {
250
278
  subQueue.forEach((effect, item) => {
251
279
  effect.runIfDirty();
252
- subQueue.delete(item);
280
+ queue.delete(item);
253
281
  });
254
282
  return {
255
283
  finished: true,
@@ -269,7 +297,7 @@ class MacroScheduler extends Scheduler {
269
297
  const task = () => {
270
298
  subQueue.forEach((effect, item) => {
271
299
  effect.runIfDirty();
272
- subQueue.delete(item);
300
+ queue.delete(item);
273
301
  });
274
302
  };
275
303
  task.time = Date.now();
@@ -285,7 +313,7 @@ class LayoutScheduler extends Scheduler {
285
313
  const task = () => {
286
314
  subQueue.forEach((effect, item) => {
287
315
  effect.runIfDirty();
288
- subQueue.delete(item);
316
+ queue.delete(item);
289
317
  });
290
318
  };
291
319
  task.time = Date.now();
@@ -300,19 +328,19 @@ const _scheduler = {
300
328
  };
301
329
  const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
302
330
 
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) => {
331
+ var __defProp$2 = Object.defineProperty;
332
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
333
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
334
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
335
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
336
+ var __spreadValues$2 = (a, b) => {
309
337
  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]);
338
+ if (__hasOwnProp$3.call(b, prop))
339
+ __defNormalProp$2(a, prop, b[prop]);
340
+ if (__getOwnPropSymbols$3)
341
+ for (var prop of __getOwnPropSymbols$3(b)) {
342
+ if (__propIsEnum$3.call(b, prop))
343
+ __defNormalProp$2(a, prop, b[prop]);
316
344
  }
317
345
  return a;
318
346
  };
@@ -325,7 +353,7 @@ const DefaultDFSOpt = {
325
353
  breakNode: null
326
354
  };
327
355
  function dfs(root, opt = {}) {
328
- const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$1(__spreadValues$1({}, DefaultDFSOpt), opt);
356
+ const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$2(__spreadValues$2({}, DefaultDFSOpt), opt);
329
357
  let node = opt.breakNode || root;
330
358
  let line = breakLine;
331
359
  const listKey = isUp ? "recStart" : "emitStart";
@@ -611,27 +639,49 @@ function clean(cb) {
611
639
  function runWithPulling(fn, signal) {
612
640
  const prevPulling = G.PullingSignal;
613
641
  G.PullingSignal = signal;
614
- fn();
642
+ const res = fn();
615
643
  G.PullingSignal = prevPulling;
644
+ return res;
616
645
  }
617
646
 
618
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
619
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
620
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
647
+ class Batch {
648
+ constructor() {
649
+ this.deep = 0;
650
+ }
651
+ start() {
652
+ this.deep++;
653
+ }
654
+ end() {
655
+ this.deep--;
656
+ if (this.deep !== 0) return;
657
+ for (const key in _scheduler) {
658
+ const instance = _scheduler[key];
659
+ instance.endSet();
660
+ }
661
+ }
662
+ inBatch() {
663
+ return this.deep > 0;
664
+ }
665
+ }
666
+ const batch = new Batch();
667
+
668
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
669
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
670
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
621
671
  var __objRest = (source, exclude) => {
622
672
  var target = {};
623
673
  for (var prop in source)
624
- if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
674
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
625
675
  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))
676
+ if (source != null && __getOwnPropSymbols$2)
677
+ for (var prop of __getOwnPropSymbols$2(source)) {
678
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
629
679
  target[prop] = source[prop];
630
680
  }
631
681
  return target;
632
682
  };
633
683
  const markDeep = (signal) => {
634
- let level = 0, firstEffectItem, lastEffectItem, updatedSchedulers = /* @__PURE__ */ new Set();
684
+ let level = 0, updatedSchedulers = /* @__PURE__ */ new Set();
635
685
  dfs(signal, {
636
686
  isUp: false,
637
687
  begin: ({ node }) => {
@@ -651,18 +701,19 @@ const markDeep = (signal) => {
651
701
  const key = node.scheduler;
652
702
  const instance = _scheduler[key];
653
703
  const item = instance.addEffect(node);
654
- if (!firstEffectItem) {
655
- firstEffectItem = item;
704
+ if (!instance.firstEffectItem) {
705
+ instance.firstEffectItem = item;
656
706
  }
657
- lastEffectItem = item;
707
+ instance.lastEffectItem = item;
658
708
  updatedSchedulers.add(key);
659
709
  }
660
710
  level++;
661
711
  }
662
712
  });
663
- for (const key of updatedSchedulers) {
713
+ if (batch.inBatch()) return;
714
+ for (const key in _scheduler) {
664
715
  const instance = _scheduler[key];
665
- instance == null ? void 0 : instance.onOneSetEffectsAdded(instance.effectQueue.subRef(firstEffectItem, lastEffectItem), instance.effectQueue);
716
+ instance.endSet();
666
717
  }
667
718
  };
668
719
  const pullingPostprocess = (node) => {
@@ -693,13 +744,16 @@ const _Signal = class _Signal {
693
744
  this.clean = null;
694
745
  }
695
746
  static create(nextValue, _a) {
696
- var _b = _a, { customPull, isScope, immediate } = _b, rest = __objRest(_b, ["customPull", "isScope", "immediate"]);
747
+ var _b = _a, { customPull, isScope, scope, immediate } = _b, rest = __objRest(_b, ["customPull", "isScope", "scope", "immediate"]);
697
748
  const s = new _Signal(nextValue, customPull);
698
749
  s.pull = s.customPull || s.DEFAULT_PULL;
699
750
  Object.assign(s, rest);
700
751
  if (isScope) {
701
752
  s.state |= State.IsScope;
702
753
  }
754
+ if (scope !== void 0) {
755
+ s.scope = scope;
756
+ }
703
757
  return s;
704
758
  }
705
759
  DEFAULT_PULL() {
@@ -844,53 +898,486 @@ const _Signal = class _Signal {
844
898
  _Signal.Pulling = null;
845
899
  let Signal = _Signal;
846
900
 
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) => {
901
+ var __defProp$1 = Object.defineProperty;
902
+ var __defProps = Object.defineProperties;
903
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
904
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
905
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
906
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
907
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
908
+ var __spreadValues$1 = (a, b) => {
909
+ for (var prop in b || (b = {}))
910
+ if (__hasOwnProp$1.call(b, prop))
911
+ __defNormalProp$1(a, prop, b[prop]);
912
+ if (__getOwnPropSymbols$1)
913
+ for (var prop of __getOwnPropSymbols$1(b)) {
914
+ if (__propIsEnum$1.call(b, prop))
915
+ __defNormalProp$1(a, prop, b[prop]);
916
+ }
917
+ return a;
918
+ };
919
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
920
+ const deepSignal = (target, scope, deep = true) => {
921
+ var _a;
855
922
  const isObj = typeof target === "object" && target !== null;
856
- if (!isObj) return target;
857
- if (proxyMap.has(target)) return proxyMap.get(target);
923
+ if (!isObj || target[Keys.Raw]) return target;
924
+ if (rawToProxy.has(target)) return rawToProxy.get(target);
858
925
  const cells = /* @__PURE__ */ new Map();
926
+ const targetIsArray = Array.isArray(target);
927
+ const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
859
928
  const proxy = new Proxy(target, {
860
929
  get(obj, prop, receiver) {
861
- if (prop === Keys.Raw) {
862
- return target;
930
+ switch (prop) {
931
+ case Keys.Raw:
932
+ return target;
933
+ case Keys.Deep:
934
+ return deep;
935
+ case Keys.Scope:
936
+ return scope;
937
+ case Keys.Cells:
938
+ return cells;
939
+ }
940
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
941
+ return Reflect.get(obj, prop, receiver);
942
+ }
943
+ const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
944
+ const isGetter = desc && typeof desc.get === "function";
945
+ if (isGetter) {
946
+ return handleGetterAsComputed(obj, prop, receiver, cells, scope);
947
+ }
948
+ const value = Reflect.get(obj, prop, receiver);
949
+ const valueIsFn = typeof value === "function";
950
+ if (valueIsFn) {
951
+ if (targetIsArray) {
952
+ return arrayMethodReWrites[prop] || value;
953
+ } else {
954
+ return value;
955
+ }
863
956
  }
864
957
  if (cells.has(prop)) {
865
958
  return cells.get(prop).v;
866
959
  }
867
- const value = Reflect.get(obj, prop, receiver);
868
- const wrappedValue = deep ? deepSignal(value) : value;
960
+ const wrappedValue = deep ? deepSignal(value, scope) : value;
869
961
  const s = Signal.create(wrappedValue, {
870
962
  scheduler: Scheduler.Sync,
871
- isScope: false
963
+ isScope: false,
964
+ scope
872
965
  });
873
966
  cells.set(prop, s);
874
967
  return s.v;
875
968
  },
876
969
  set(obj, prop, value, receiver) {
970
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
971
+ return Reflect.set(obj, prop, value, receiver);
972
+ }
973
+ batch.start();
974
+ const success = Reflect.set(obj, prop, value, receiver);
877
975
  if (cells.has(prop)) {
878
976
  const cell = cells.get(prop);
879
- cell.v = deep ? deepSignal(value) : value;
977
+ cell.v = deep ? deepSignal(value, scope) : value;
880
978
  }
881
- return Reflect.set(obj, prop, value, receiver);
979
+ if (targetIsArray) {
980
+ handleArraySet(obj, prop, value, receiver);
981
+ }
982
+ batch.end();
983
+ return success;
882
984
  },
883
985
  // 【核心修改】拦截 delete 操作
884
986
  deleteProperty(obj, prop) {
987
+ if (targetIsStore && obj.constructor[StoreIgnoreKeys].includes(prop)) {
988
+ return Reflect.deleteProperty(obj, prop);
989
+ }
885
990
  if (cells.has(prop)) {
886
991
  cells.delete(prop);
887
992
  }
888
993
  return Reflect.deleteProperty(obj, prop);
994
+ },
995
+ ownKeys(obj) {
996
+ if (targetIsArray) {
997
+ proxy.length;
998
+ } else {
999
+ proxy[Keys.Iterator];
1000
+ }
1001
+ return Reflect.ownKeys(obj);
889
1002
  }
890
1003
  });
891
- proxyMap.set(target, proxy);
1004
+ rawToProxy.set(target, proxy);
892
1005
  return proxy;
893
1006
  };
1007
+ const shareSignal = (from, fromPath, to, toPath) => {
1008
+ try {
1009
+ const toPaths = toPath.split(".");
1010
+ const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
1011
+ runWithPulling(() => {
1012
+ const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
1013
+ fromTarget[fromKey];
1014
+ const fromSignal = fromTarget[Keys.Cells].get(fromKey);
1015
+ const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1016
+ toTarget[Keys.Cells].set(toKey, fromSignal);
1017
+ }, null);
1018
+ } catch (error) {
1019
+ console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
1020
+ throw error;
1021
+ }
1022
+ };
1023
+ function getTargetAndKey(obj, paths) {
1024
+ let target = obj;
1025
+ let key = "";
1026
+ const len = paths.length;
1027
+ for (let i = 0; i < len; i++) {
1028
+ key = paths[i];
1029
+ if (i < len - 1) {
1030
+ target = target[key];
1031
+ }
1032
+ }
1033
+ return { target, key };
1034
+ }
1035
+ function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1036
+ if (cells.has(prop)) {
1037
+ return cells.get(prop).v;
1038
+ }
1039
+ const s = Signal.create(null, {
1040
+ customPull: () => Reflect.get(obj, prop, receiver),
1041
+ scheduler: Scheduler.Sync,
1042
+ isScope: false,
1043
+ scope
1044
+ });
1045
+ cells.set(prop, s);
1046
+ return s.v;
1047
+ }
1048
+ function handleArraySet(arr, prop, value, receiver) {
1049
+ if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
1050
+ receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
1051
+ } else ;
1052
+ }
1053
+ const arrayMethodReWrites = {};
1054
+ ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
1055
+ arrayMethodReWrites[key] = function(...args) {
1056
+ batch.start();
1057
+ const fn = Array.prototype[key];
1058
+ const res = runWithPulling(() => fn.call(this, ...args), null);
1059
+ this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
1060
+ batch.end();
1061
+ return res;
1062
+ };
1063
+ });
1064
+ ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
1065
+ arrayMethodReWrites[key] = function(...args) {
1066
+ const fn = Array.prototype[key];
1067
+ const that = toRaw(this);
1068
+ let result = fn.call(that, ...args);
1069
+ const value = args[0];
1070
+ if ((result === false || result === -1) && typeof value === "object" && value !== null) {
1071
+ if (value[Keys.Raw]) {
1072
+ args[0] = value[Keys.Raw];
1073
+ result = fn.call(that, ...args);
1074
+ }
1075
+ if (rawToProxy.has(value)) {
1076
+ args[0] = rawToProxy.get(value);
1077
+ result = fn.call(that, ...args);
1078
+ }
1079
+ }
1080
+ this[Keys.Iterator];
1081
+ return result;
1082
+ };
1083
+ });
1084
+ [Symbol.iterator, "values", "entries"].forEach((key) => {
1085
+ const isEntries = key === "entries";
1086
+ arrayMethodReWrites[key] = function(...args) {
1087
+ const fn = Array.prototype[key];
1088
+ const rawArray = toRaw(this);
1089
+ const iter = fn.call(rawArray, ...args);
1090
+ const scope = this[Keys.Scope];
1091
+ const isDeep = this[Keys.Deep];
1092
+ if (isDeep) {
1093
+ const rawNext = iter.next.bind(iter);
1094
+ iter.next = () => {
1095
+ const result = rawNext();
1096
+ if (!result.done) {
1097
+ if (isEntries) {
1098
+ result.value[1] = deepSignal(result.value[1], scope);
1099
+ } else {
1100
+ result.value = deepSignal(result.value, scope);
1101
+ }
1102
+ }
1103
+ return result;
1104
+ };
1105
+ }
1106
+ this[Keys.Iterator];
1107
+ return iter;
1108
+ };
1109
+ });
1110
+ arrayMethodReWrites.filter = function(callback, thisArg) {
1111
+ const scope = this[Keys.Scope];
1112
+ const isDeep = this[Keys.Deep];
1113
+ const that = toRaw(this);
1114
+ const result = [];
1115
+ let resultIndex = 0;
1116
+ const userThis = thisArg || that;
1117
+ const len = that.length;
1118
+ for (let i = 0; i < len; i++) {
1119
+ if (i in that) {
1120
+ const value = isDeep ? deepSignal(that[i], scope) : that[i];
1121
+ if (callback.call(userThis, value, i, userThis)) {
1122
+ result[resultIndex++] = value;
1123
+ }
1124
+ }
1125
+ }
1126
+ this[Keys.Iterator];
1127
+ return result;
1128
+ };
1129
+ arrayMethodReWrites.slice = function(start, end) {
1130
+ const scope = this[Keys.Scope];
1131
+ const isDeep = this[Keys.Deep];
1132
+ const that = toRaw(this);
1133
+ const len = that.length;
1134
+ let k = start || 0;
1135
+ if (k < 0) {
1136
+ k = Math.max(len + k, 0);
1137
+ } else {
1138
+ k = Math.min(k, len);
1139
+ }
1140
+ let final = end === void 0 ? len : end;
1141
+ if (final < 0) {
1142
+ final = Math.max(len + final, 0);
1143
+ } else {
1144
+ final = Math.min(final, len);
1145
+ }
1146
+ const count = Math.max(final - k, 0);
1147
+ const result = new Array(count);
1148
+ for (let i = 0; i < count; i++) {
1149
+ if (i + k in that) {
1150
+ result[i] = isDeep ? deepSignal(that[i + k], scope) : that[i + k];
1151
+ }
1152
+ }
1153
+ this[Keys.Iterator];
1154
+ return result;
1155
+ };
1156
+ arrayMethodReWrites.toReversed = function() {
1157
+ const scope = this[Keys.Scope];
1158
+ const isDeep = this[Keys.Deep];
1159
+ const that = toRaw(this);
1160
+ const len = that.length;
1161
+ const result = new Array(len);
1162
+ let k = 0;
1163
+ while (k < len) {
1164
+ result[k] = isDeep ? deepSignal(that[len - 1 - k], scope) : that[len - 1 - k];
1165
+ k++;
1166
+ }
1167
+ this[Keys.Iterator];
1168
+ return result;
1169
+ };
1170
+ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1171
+ const scope = this[Keys.Scope];
1172
+ const isDeep = this[Keys.Deep];
1173
+ const that = toRaw(this);
1174
+ const len = that.length;
1175
+ let relativeStart = start >> 0;
1176
+ let actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
1177
+ let actualDeleteCount;
1178
+ if (arguments.length === 0) {
1179
+ actualDeleteCount = 0;
1180
+ } else if (arguments.length === 1) {
1181
+ actualDeleteCount = len - actualStart;
1182
+ } else {
1183
+ let dc = deleteCount >> 0;
1184
+ actualDeleteCount = Math.min(Math.max(dc, 0), len - actualStart);
1185
+ }
1186
+ const insertCount = items.length;
1187
+ const newLen = len - actualDeleteCount + insertCount;
1188
+ const result = new Array(newLen);
1189
+ for (let i = 0; i < actualStart; i++) {
1190
+ result[i] = isDeep ? deepSignal(that[i], scope) : that[i];
1191
+ }
1192
+ for (let i = 0; i < insertCount; i++) {
1193
+ result[actualStart + i] = isDeep ? deepSignal(items[i], scope) : items[i];
1194
+ }
1195
+ const remainingStart = actualStart + actualDeleteCount;
1196
+ const resultOffset = actualStart + insertCount;
1197
+ for (let i = 0; i < len - remainingStart; i++) {
1198
+ result[resultOffset + i] = isDeep ? deepSignal(that[remainingStart + i], scope) : that[remainingStart + i];
1199
+ }
1200
+ this[Keys.Iterator];
1201
+ return result;
1202
+ };
1203
+ arrayMethodReWrites.with = function(index, value) {
1204
+ const scope = this[Keys.Scope];
1205
+ const isDeep = this[Keys.Deep];
1206
+ const that = toRaw(this);
1207
+ const len = that.length;
1208
+ let relativeIndex = Number(index) || 0;
1209
+ let actualIndex = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
1210
+ if (actualIndex >= len || actualIndex < 0) {
1211
+ throw new RangeError(`Invalid index: ${index}`);
1212
+ }
1213
+ const result = new Array(len);
1214
+ for (let i = 0; i < len; i++) {
1215
+ if (i === actualIndex) {
1216
+ result[i] = isDeep ? deepSignal(value, scope) : value;
1217
+ } else {
1218
+ result[i] = isDeep ? deepSignal(that[i], scope) : that[i];
1219
+ }
1220
+ }
1221
+ this[Keys.Iterator];
1222
+ return result;
1223
+ };
1224
+ arrayMethodReWrites.concat = function(...items) {
1225
+ const scope = this[Keys.Scope];
1226
+ const isDeep = this[Keys.Deep];
1227
+ const that = toRaw(this);
1228
+ const selfLen = that.length;
1229
+ let totalLength = selfLen;
1230
+ for (let i = 0; i < items.length; i++) {
1231
+ const item = items[i];
1232
+ if (Array.isArray(item)) {
1233
+ totalLength += item.length;
1234
+ } else {
1235
+ totalLength += 1;
1236
+ }
1237
+ }
1238
+ const result = new Array(totalLength);
1239
+ let k = 0;
1240
+ for (; k < selfLen; k++) {
1241
+ if (k in that) {
1242
+ result[k] = isDeep ? deepSignal(that[k], scope) : that[k];
1243
+ }
1244
+ }
1245
+ for (let i = 0; i < items.length; i++) {
1246
+ const item = items[i];
1247
+ if (Array.isArray(item)) {
1248
+ for (let j = 0; j < item.length; j++) {
1249
+ if (j in item) {
1250
+ result[k] = isDeep ? deepSignal(item[j], scope) : item[j];
1251
+ }
1252
+ k++;
1253
+ }
1254
+ } else {
1255
+ result[k] = isDeep ? deepSignal(item, scope) : item;
1256
+ k++;
1257
+ }
1258
+ }
1259
+ this[Keys.Iterator];
1260
+ return result;
1261
+ };
1262
+ const GetMethodConf = {
1263
+ wrapReturn: false,
1264
+ wrapArgs: 1
1265
+ };
1266
+ [
1267
+ __spreadValues$1({
1268
+ key: "every"
1269
+ }, GetMethodConf),
1270
+ __spreadValues$1({
1271
+ key: "find",
1272
+ wrapReturn: true
1273
+ }, GetMethodConf),
1274
+ __spreadProps(__spreadValues$1({
1275
+ key: "findLast"
1276
+ }, GetMethodConf), {
1277
+ wrapReturn: true
1278
+ }),
1279
+ __spreadValues$1({
1280
+ key: "findIndex"
1281
+ }, GetMethodConf),
1282
+ __spreadValues$1({
1283
+ key: "findLastIndex"
1284
+ }, GetMethodConf),
1285
+ __spreadValues$1({
1286
+ key: "forEach"
1287
+ }, GetMethodConf),
1288
+ __spreadValues$1({
1289
+ key: "map"
1290
+ }, GetMethodConf),
1291
+ __spreadValues$1({
1292
+ key: "some"
1293
+ }, GetMethodConf),
1294
+ __spreadProps(__spreadValues$1({
1295
+ key: "reduce"
1296
+ }, GetMethodConf), {
1297
+ wrapArgs: 2
1298
+ }),
1299
+ __spreadProps(__spreadValues$1({
1300
+ key: "reduceRight"
1301
+ }, GetMethodConf), {
1302
+ wrapArgs: 2
1303
+ })
1304
+ ].forEach(({ key, wrapReturn, wrapArgs }) => {
1305
+ arrayMethodReWrites[key] = function(...args) {
1306
+ const scope = this[Keys.Scope];
1307
+ const fn = Array.prototype[key];
1308
+ const isDeep = this[Keys.Deep];
1309
+ const that = toRaw(this);
1310
+ warpCallbackArgs(isDeep, args, scope, wrapArgs);
1311
+ let result = fn.call(that, ...args);
1312
+ if (wrapReturn && isDeep) {
1313
+ result = deepSignal(result, scope);
1314
+ }
1315
+ this[Keys.Iterator];
1316
+ return result;
1317
+ };
1318
+ });
1319
+ arrayMethodReWrites.toSorted = function(...args) {
1320
+ const fn = Array.prototype["toSorted"];
1321
+ const scope = this[Keys.Scope];
1322
+ const isDeep = this[Keys.Deep];
1323
+ const that = toRaw(this);
1324
+ warpCallbackArgs(isDeep, args, scope, 3);
1325
+ let result = fn.call(that, ...args);
1326
+ this[Keys.Iterator];
1327
+ return isDeep ? result.map((it) => deepSignal(it, scope)) : result;
1328
+ };
1329
+ ["join", "toString", "toLocaleString"].forEach((key) => {
1330
+ arrayMethodReWrites[key] = function(...args) {
1331
+ const fn = Array.prototype[key];
1332
+ const that = toRaw(this);
1333
+ const result = fn.call(that, ...args);
1334
+ this[Keys.Iterator];
1335
+ return result;
1336
+ };
1337
+ });
1338
+ function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
1339
+ const callback = args[0];
1340
+ const wrapCb = function(...cbArgs) {
1341
+ if (isDeep) {
1342
+ if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
1343
+ if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
1344
+ }
1345
+ return callback.call(this, ...cbArgs);
1346
+ };
1347
+ args[0] = wrapCb;
1348
+ }
1349
+
1350
+ var _a, _b;
1351
+ _b = IsStore, _a = StoreIgnoreKeys;
1352
+ const _Store = class _Store {
1353
+ constructor() {
1354
+ const proxy = deepSignal(this, G.PullingSignal, true);
1355
+ _Store.Current = proxy;
1356
+ return proxy;
1357
+ }
1358
+ static new(keyMap = {}) {
1359
+ const parentStore = _Store.Current;
1360
+ const child = new this();
1361
+ if (parentStore) {
1362
+ for (const childKey in keyMap) {
1363
+ const parentKey = keyMap[childKey];
1364
+ shareSignal(parentStore, parentKey, child, childKey);
1365
+ }
1366
+ }
1367
+ _Store.Current = parentStore;
1368
+ return child;
1369
+ }
1370
+ set(fn) {
1371
+ effect(() => {
1372
+ const props = fn();
1373
+ Object.assign(this, props);
1374
+ });
1375
+ }
1376
+ };
1377
+ _Store[_b] = true;
1378
+ _Store[_a] = ["ui", "raw"];
1379
+ _Store.Current = null;
1380
+ let Store = _Store;
894
1381
 
895
1382
  var __defProp = Object.defineProperty;
896
1383
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -927,7 +1414,7 @@ const $ = (init, opt = {}) => {
927
1414
  intiValue = null;
928
1415
  customPull = init;
929
1416
  } else if (opt.mode !== "ref" && typeof init === "object" && init !== null) {
930
- return deepSignal(init, opt.deep);
1417
+ return deepSignal(init, G.PullingSignal, opt.deep);
931
1418
  } else {
932
1419
  intiValue = init;
933
1420
  }
@@ -1004,9 +1491,13 @@ const isScope = (value) => {
1004
1491
  };
1005
1492
 
1006
1493
  exports.$ = $;
1494
+ exports.IsStore = IsStore;
1007
1495
  exports.Keys = Keys;
1008
1496
  exports.Scheduler = Scheduler;
1497
+ exports.Store = Store;
1498
+ exports.StoreIgnoreKeys = StoreIgnoreKeys;
1009
1499
  exports.TaskQueue = TaskQueue;
1500
+ exports.batch = batch;
1010
1501
  exports.clean = clean;
1011
1502
  exports.customEffect = customEffect;
1012
1503
  exports.effect = effect;