aoye 0.0.19 → 0.0.20
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 +42 -23
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +41 -24
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.umd.js +42 -23
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/aoye.cjs.js
CHANGED
|
@@ -243,9 +243,9 @@ class Scheduler {
|
|
|
243
243
|
var _a;
|
|
244
244
|
if (!this.firstEffectItem) return;
|
|
245
245
|
const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
|
|
246
|
-
(_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
|
|
247
246
|
this.firstEffectItem = null;
|
|
248
247
|
this.lastEffectItem = null;
|
|
248
|
+
(_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
|
|
249
249
|
}
|
|
250
250
|
addEffect(effect) {
|
|
251
251
|
var _a;
|
|
@@ -261,8 +261,8 @@ Scheduler.Macro = "__Macro_";
|
|
|
261
261
|
class SyncScheduler extends Scheduler {
|
|
262
262
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
263
263
|
subQueue.forEach((effect, item) => {
|
|
264
|
-
effect.runIfDirty();
|
|
265
264
|
queue.delete(item);
|
|
265
|
+
effect.runIfDirty();
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
}
|
|
@@ -274,8 +274,8 @@ class MicroScheduler extends Scheduler {
|
|
|
274
274
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
275
275
|
const task = () => {
|
|
276
276
|
subQueue.forEach((effect, item) => {
|
|
277
|
-
effect.runIfDirty();
|
|
278
277
|
queue.delete(item);
|
|
278
|
+
effect.runIfDirty();
|
|
279
279
|
});
|
|
280
280
|
return {
|
|
281
281
|
finished: true,
|
|
@@ -294,8 +294,8 @@ class MacroScheduler extends Scheduler {
|
|
|
294
294
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
295
295
|
const task = () => {
|
|
296
296
|
subQueue.forEach((effect, item) => {
|
|
297
|
-
effect.runIfDirty();
|
|
298
297
|
queue.delete(item);
|
|
298
|
+
effect.runIfDirty();
|
|
299
299
|
});
|
|
300
300
|
};
|
|
301
301
|
task.time = Date.now();
|
|
@@ -310,8 +310,8 @@ class LayoutScheduler extends Scheduler {
|
|
|
310
310
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
311
311
|
const task = () => {
|
|
312
312
|
subQueue.forEach((effect, item) => {
|
|
313
|
-
effect.runIfDirty();
|
|
314
313
|
queue.delete(item);
|
|
314
|
+
effect.runIfDirty();
|
|
315
315
|
});
|
|
316
316
|
};
|
|
317
317
|
task.time = Date.now();
|
|
@@ -324,6 +324,7 @@ const _scheduler = {
|
|
|
324
324
|
[Scheduler.Macro]: new MacroScheduler(),
|
|
325
325
|
[Scheduler.Layout]: new LayoutScheduler()
|
|
326
326
|
};
|
|
327
|
+
globalThis["sche"] = _scheduler[Scheduler.Sync];
|
|
327
328
|
const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
|
|
328
329
|
|
|
329
330
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -712,6 +713,9 @@ const markDeep = (signal) => {
|
|
|
712
713
|
updatedSchedulers.add(key);
|
|
713
714
|
}
|
|
714
715
|
level++;
|
|
716
|
+
if (isLeaf) {
|
|
717
|
+
return true;
|
|
718
|
+
}
|
|
715
719
|
}
|
|
716
720
|
});
|
|
717
721
|
if (batch.inBatch()) return;
|
|
@@ -771,13 +775,7 @@ const _Signal = class _Signal {
|
|
|
771
775
|
var _a, _b;
|
|
772
776
|
G.PullingRecurseDeep++;
|
|
773
777
|
const downstream = G.PullingSignal;
|
|
774
|
-
|
|
775
|
-
if (this !== downstream && // 1. 外部支持 link
|
|
776
|
-
shouldLink && // 2. 有下游
|
|
777
|
-
downstream && // 3. 下游是 watcher,不链接非 scope
|
|
778
|
-
((downstream.state & State.LinkScopeOnly) === 0 || isScope)) {
|
|
779
|
-
Line.link(this, downstream);
|
|
780
|
-
}
|
|
778
|
+
this.linkWhenPull(downstream);
|
|
781
779
|
try {
|
|
782
780
|
if (this.version === G.version) {
|
|
783
781
|
return this.value;
|
|
@@ -788,7 +786,7 @@ const _Signal = class _Signal {
|
|
|
788
786
|
(_a = this.clean) == null ? void 0 : _a.call(this);
|
|
789
787
|
this.clean = null;
|
|
790
788
|
let v = this.pull();
|
|
791
|
-
if (
|
|
789
|
+
if (this.state & State.IsScope && typeof v === "function") {
|
|
792
790
|
const fn = v;
|
|
793
791
|
this.clean = () => runWithPulling(fn, null);
|
|
794
792
|
v = this.value;
|
|
@@ -808,6 +806,20 @@ const _Signal = class _Signal {
|
|
|
808
806
|
G.PullingRecurseDeep--;
|
|
809
807
|
}
|
|
810
808
|
}
|
|
809
|
+
linkWhenPull(downstream) {
|
|
810
|
+
const isScope = this.state & State.IsScope;
|
|
811
|
+
if (this !== downstream && // 2. 有下游
|
|
812
|
+
downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
813
|
+
((downstream.state & State.LinkScopeOnly) === 0 || isScope) && /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
|
|
814
|
+
* 发生在 outEffect(() => scope(() => innerEffect(), null))
|
|
815
|
+
* 虽然通过 scope 让 innerEffect 被管理,
|
|
816
|
+
* 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
|
|
817
|
+
* 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
|
|
818
|
+
*/
|
|
819
|
+
(!isScope || !this.emitStart)) {
|
|
820
|
+
Line.link(this, downstream);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
811
823
|
pullDeep() {
|
|
812
824
|
const signal = this;
|
|
813
825
|
if (signal.state & DirtyState) {
|
|
@@ -856,11 +868,7 @@ const _Signal = class _Signal {
|
|
|
856
868
|
});
|
|
857
869
|
}
|
|
858
870
|
const downstream = G.PullingSignal;
|
|
859
|
-
|
|
860
|
-
downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
861
|
-
((downstream.state & State.LinkScopeOnly) === 0 || this.state & State.IsScope)) {
|
|
862
|
-
Line.link(this, downstream);
|
|
863
|
-
}
|
|
871
|
+
this.linkWhenPull(downstream);
|
|
864
872
|
return this.value;
|
|
865
873
|
}
|
|
866
874
|
get v() {
|
|
@@ -1028,10 +1036,11 @@ const shareSignal = (from, fromPath, to, toPath) => {
|
|
|
1028
1036
|
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1029
1037
|
runWithPulling(() => {
|
|
1030
1038
|
const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
|
|
1031
|
-
fromTarget[fromKey];
|
|
1039
|
+
const val = fromTarget[fromKey];
|
|
1032
1040
|
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1033
1041
|
const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
|
|
1034
1042
|
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1043
|
+
toTarget[Keys.Raw][toKey] = val;
|
|
1035
1044
|
}, null);
|
|
1036
1045
|
} catch (error) {
|
|
1037
1046
|
console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
|
|
@@ -1509,13 +1518,21 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1509
1518
|
bound.ins = s;
|
|
1510
1519
|
return bound;
|
|
1511
1520
|
};
|
|
1512
|
-
const scope = (
|
|
1521
|
+
const scope = (...args) => {
|
|
1522
|
+
const hasScope = args.length > 1;
|
|
1513
1523
|
const s = Signal.create(null, {
|
|
1514
|
-
customPull,
|
|
1524
|
+
customPull: args[0],
|
|
1515
1525
|
scheduler: Scheduler.Sync,
|
|
1516
|
-
isScope: true
|
|
1526
|
+
isScope: true,
|
|
1527
|
+
scope: hasScope ? args[1] : G.PullingSignal
|
|
1517
1528
|
});
|
|
1518
|
-
|
|
1529
|
+
if (hasScope) {
|
|
1530
|
+
runWithPulling(() => {
|
|
1531
|
+
s.v;
|
|
1532
|
+
}, args[1]);
|
|
1533
|
+
} else {
|
|
1534
|
+
s.v;
|
|
1535
|
+
}
|
|
1519
1536
|
s.state |= State.ScopeReady;
|
|
1520
1537
|
const bound = dispose.bind(s);
|
|
1521
1538
|
bound.ins = s;
|
|
@@ -1537,6 +1554,7 @@ exports.$ = $;
|
|
|
1537
1554
|
exports.IsStore = IsStore;
|
|
1538
1555
|
exports.Keys = Keys;
|
|
1539
1556
|
exports.Scheduler = Scheduler;
|
|
1557
|
+
exports.Signal = Signal;
|
|
1540
1558
|
exports.Store = Store;
|
|
1541
1559
|
exports.StoreIgnoreKeys = StoreIgnoreKeys;
|
|
1542
1560
|
exports.TaskQueue = TaskQueue;
|
|
@@ -1553,4 +1571,5 @@ exports.runWithPulling = runWithPulling;
|
|
|
1553
1571
|
exports.scope = scope;
|
|
1554
1572
|
exports.setPulling = setPulling;
|
|
1555
1573
|
exports.shareSignal = shareSignal;
|
|
1574
|
+
exports.toRaw = toRaw;
|
|
1556
1575
|
//# sourceMappingURL=aoye.cjs.js.map
|