aoye 0.0.19 → 0.0.21
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/index.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ type ValueDiff = {
|
|
|
88
88
|
old: any;
|
|
89
89
|
val: any;
|
|
90
90
|
};
|
|
91
|
+
type CreateScope = (customPull: () => void, scope?: Signal) => Dispose;
|
|
91
92
|
type Dispose = {
|
|
92
93
|
(): void;
|
|
93
94
|
ins: Signal;
|
|
@@ -135,7 +136,7 @@ declare class Line {
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
declare class Signal<T = any> implements Vertex {
|
|
138
|
-
|
|
139
|
+
nextValue: T;
|
|
139
140
|
/** 为什么是 shallow,因为 pullDeep 会把
|
|
140
141
|
* 上游节点 get 执行完成,让其可以直接拿到缓存值
|
|
141
142
|
*/
|
|
@@ -165,6 +166,7 @@ declare class Signal<T = any> implements Vertex {
|
|
|
165
166
|
* 递归拉取负责建立以来链
|
|
166
167
|
*/
|
|
167
168
|
pullRecurse(shouldLink?: boolean): T;
|
|
169
|
+
linkWhenPull(downstream: Signal): void;
|
|
168
170
|
pullDeep(): T;
|
|
169
171
|
get v(): T;
|
|
170
172
|
markDownStreamsDirty(): void;
|
|
@@ -257,6 +259,8 @@ declare class Batch {
|
|
|
257
259
|
}
|
|
258
260
|
declare const batch: Batch;
|
|
259
261
|
|
|
262
|
+
declare const toRaw: <T>(a: T) => any;
|
|
263
|
+
|
|
260
264
|
declare const DefaultCustomSignalOpt: {
|
|
261
265
|
/** 三种模式
|
|
262
266
|
* 1. auto: 根据值类型自动判断 默认
|
|
@@ -281,7 +285,7 @@ type CreateSignal = {
|
|
|
281
285
|
};
|
|
282
286
|
declare const $: CreateSignal;
|
|
283
287
|
declare const effect: (customPull: (...args: ValueDiff[]) => void, depOrOpt?: Signal<any>[] | CustomEffectOpt, opt?: CustomEffectOpt) => Dispose;
|
|
284
|
-
declare const scope:
|
|
288
|
+
declare const scope: CreateScope;
|
|
285
289
|
/**
|
|
286
290
|
* 数据变化时,自定义 触发订阅函数的时机
|
|
287
291
|
* @param {CustomSignalOpt} opt 配置如下:
|
|
@@ -292,5 +296,5 @@ declare const customEffect: (opt?: CustomEffectOpt) => typeof effect;
|
|
|
292
296
|
declare const isSignal: (value: unknown) => value is Signal;
|
|
293
297
|
declare const isScope: (value: any) => boolean;
|
|
294
298
|
|
|
295
|
-
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal };
|
|
296
|
-
export type { CreateSignal, CreateTaskProps, CustomEffectOpt, CustomSignalOpt, DFSCtxBegin, DFSCtxCompete, DeepOmitPath, DeepPath, DeepValue, Dispose, Getter, Key, MatchValue, Mix, PRecord, ScheduleHandler, SignalOpt, SignalType, Task, TaskControlReturn, ValueDiff, Vertex };
|
|
299
|
+
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal, toRaw };
|
|
300
|
+
export type { CreateScope, CreateSignal, CreateTaskProps, CustomEffectOpt, CustomSignalOpt, DFSCtxBegin, DFSCtxCompete, DeepOmitPath, DeepPath, DeepValue, Dispose, Getter, Key, MatchValue, Mix, PRecord, ScheduleHandler, SignalOpt, SignalType, Task, TaskControlReturn, ValueDiff, Vertex };
|
package/dist/index.umd.js
CHANGED
|
@@ -245,9 +245,9 @@
|
|
|
245
245
|
var _a;
|
|
246
246
|
if (!this.firstEffectItem) return;
|
|
247
247
|
const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
|
|
248
|
-
(_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
|
|
249
248
|
this.firstEffectItem = null;
|
|
250
249
|
this.lastEffectItem = null;
|
|
250
|
+
(_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
|
|
251
251
|
}
|
|
252
252
|
addEffect(effect) {
|
|
253
253
|
var _a;
|
|
@@ -263,8 +263,8 @@
|
|
|
263
263
|
class SyncScheduler extends Scheduler {
|
|
264
264
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
265
265
|
subQueue.forEach((effect, item) => {
|
|
266
|
-
effect.runIfDirty();
|
|
267
266
|
queue.delete(item);
|
|
267
|
+
effect.runIfDirty();
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
}
|
|
@@ -276,8 +276,8 @@
|
|
|
276
276
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
277
277
|
const task = () => {
|
|
278
278
|
subQueue.forEach((effect, item) => {
|
|
279
|
-
effect.runIfDirty();
|
|
280
279
|
queue.delete(item);
|
|
280
|
+
effect.runIfDirty();
|
|
281
281
|
});
|
|
282
282
|
return {
|
|
283
283
|
finished: true,
|
|
@@ -296,8 +296,8 @@
|
|
|
296
296
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
297
297
|
const task = () => {
|
|
298
298
|
subQueue.forEach((effect, item) => {
|
|
299
|
-
effect.runIfDirty();
|
|
300
299
|
queue.delete(item);
|
|
300
|
+
effect.runIfDirty();
|
|
301
301
|
});
|
|
302
302
|
};
|
|
303
303
|
task.time = Date.now();
|
|
@@ -312,8 +312,8 @@
|
|
|
312
312
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
313
313
|
const task = () => {
|
|
314
314
|
subQueue.forEach((effect, item) => {
|
|
315
|
-
effect.runIfDirty();
|
|
316
315
|
queue.delete(item);
|
|
316
|
+
effect.runIfDirty();
|
|
317
317
|
});
|
|
318
318
|
};
|
|
319
319
|
task.time = Date.now();
|
|
@@ -326,6 +326,7 @@
|
|
|
326
326
|
[Scheduler.Macro]: new MacroScheduler(),
|
|
327
327
|
[Scheduler.Layout]: new LayoutScheduler()
|
|
328
328
|
};
|
|
329
|
+
globalThis["sche"] = _scheduler[Scheduler.Sync];
|
|
329
330
|
const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
|
|
330
331
|
|
|
331
332
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -714,6 +715,9 @@
|
|
|
714
715
|
updatedSchedulers.add(key);
|
|
715
716
|
}
|
|
716
717
|
level++;
|
|
718
|
+
if (isLeaf) {
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
717
721
|
}
|
|
718
722
|
});
|
|
719
723
|
if (batch.inBatch()) return;
|
|
@@ -773,13 +777,7 @@
|
|
|
773
777
|
var _a, _b;
|
|
774
778
|
G.PullingRecurseDeep++;
|
|
775
779
|
const downstream = G.PullingSignal;
|
|
776
|
-
|
|
777
|
-
if (this !== downstream && // 1. 外部支持 link
|
|
778
|
-
shouldLink && // 2. 有下游
|
|
779
|
-
downstream && // 3. 下游是 watcher,不链接非 scope
|
|
780
|
-
((downstream.state & State.LinkScopeOnly) === 0 || isScope)) {
|
|
781
|
-
Line.link(this, downstream);
|
|
782
|
-
}
|
|
780
|
+
this.linkWhenPull(downstream);
|
|
783
781
|
try {
|
|
784
782
|
if (this.version === G.version) {
|
|
785
783
|
return this.value;
|
|
@@ -790,7 +788,7 @@
|
|
|
790
788
|
(_a = this.clean) == null ? void 0 : _a.call(this);
|
|
791
789
|
this.clean = null;
|
|
792
790
|
let v = this.pull();
|
|
793
|
-
if (
|
|
791
|
+
if (this.state & State.IsScope && typeof v === "function") {
|
|
794
792
|
const fn = v;
|
|
795
793
|
this.clean = () => runWithPulling(fn, null);
|
|
796
794
|
v = this.value;
|
|
@@ -810,6 +808,20 @@
|
|
|
810
808
|
G.PullingRecurseDeep--;
|
|
811
809
|
}
|
|
812
810
|
}
|
|
811
|
+
linkWhenPull(downstream) {
|
|
812
|
+
const isScope = this.state & State.IsScope;
|
|
813
|
+
if (this !== downstream && // 2. 有下游
|
|
814
|
+
downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
815
|
+
((downstream.state & State.LinkScopeOnly) === 0 || isScope) && /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
|
|
816
|
+
* 发生在 outEffect(() => scope(() => innerEffect(), null))
|
|
817
|
+
* 虽然通过 scope 让 innerEffect 被管理,
|
|
818
|
+
* 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
|
|
819
|
+
* 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
|
|
820
|
+
*/
|
|
821
|
+
(!isScope || !this.emitStart)) {
|
|
822
|
+
Line.link(this, downstream);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
813
825
|
pullDeep() {
|
|
814
826
|
const signal = this;
|
|
815
827
|
if (signal.state & DirtyState) {
|
|
@@ -858,11 +870,7 @@
|
|
|
858
870
|
});
|
|
859
871
|
}
|
|
860
872
|
const downstream = G.PullingSignal;
|
|
861
|
-
|
|
862
|
-
downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
863
|
-
((downstream.state & State.LinkScopeOnly) === 0 || this.state & State.IsScope)) {
|
|
864
|
-
Line.link(this, downstream);
|
|
865
|
-
}
|
|
873
|
+
this.linkWhenPull(downstream);
|
|
866
874
|
return this.value;
|
|
867
875
|
}
|
|
868
876
|
get v() {
|
|
@@ -1030,10 +1038,11 @@
|
|
|
1030
1038
|
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1031
1039
|
runWithPulling(() => {
|
|
1032
1040
|
const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
|
|
1033
|
-
fromTarget[fromKey];
|
|
1041
|
+
const val = fromTarget[fromKey];
|
|
1034
1042
|
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1035
1043
|
const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
|
|
1036
1044
|
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1045
|
+
toTarget[Keys.Raw][toKey] = val;
|
|
1037
1046
|
}, null);
|
|
1038
1047
|
} catch (error) {
|
|
1039
1048
|
console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
|
|
@@ -1511,13 +1520,21 @@
|
|
|
1511
1520
|
bound.ins = s;
|
|
1512
1521
|
return bound;
|
|
1513
1522
|
};
|
|
1514
|
-
const scope = (
|
|
1523
|
+
const scope = (...args) => {
|
|
1524
|
+
const hasScope = args.length > 1;
|
|
1515
1525
|
const s = Signal.create(null, {
|
|
1516
|
-
customPull,
|
|
1526
|
+
customPull: args[0],
|
|
1517
1527
|
scheduler: Scheduler.Sync,
|
|
1518
|
-
isScope: true
|
|
1528
|
+
isScope: true,
|
|
1529
|
+
scope: hasScope ? args[1] : G.PullingSignal
|
|
1519
1530
|
});
|
|
1520
|
-
|
|
1531
|
+
if (hasScope) {
|
|
1532
|
+
runWithPulling(() => {
|
|
1533
|
+
s.v;
|
|
1534
|
+
}, args[1]);
|
|
1535
|
+
} else {
|
|
1536
|
+
s.v;
|
|
1537
|
+
}
|
|
1521
1538
|
s.state |= State.ScopeReady;
|
|
1522
1539
|
const bound = dispose.bind(s);
|
|
1523
1540
|
bound.ins = s;
|
|
@@ -1539,6 +1556,7 @@
|
|
|
1539
1556
|
exports.IsStore = IsStore;
|
|
1540
1557
|
exports.Keys = Keys;
|
|
1541
1558
|
exports.Scheduler = Scheduler;
|
|
1559
|
+
exports.Signal = Signal;
|
|
1542
1560
|
exports.Store = Store;
|
|
1543
1561
|
exports.StoreIgnoreKeys = StoreIgnoreKeys;
|
|
1544
1562
|
exports.TaskQueue = TaskQueue;
|
|
@@ -1555,6 +1573,7 @@
|
|
|
1555
1573
|
exports.scope = scope;
|
|
1556
1574
|
exports.setPulling = setPulling;
|
|
1557
1575
|
exports.shareSignal = shareSignal;
|
|
1576
|
+
exports.toRaw = toRaw;
|
|
1558
1577
|
|
|
1559
1578
|
}));
|
|
1560
1579
|
//# sourceMappingURL=index.umd.js.map
|