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