aoye 0.0.24 → 0.0.26

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/index.d.ts CHANGED
@@ -1,39 +1,7 @@
1
- declare const enum State {
2
- Clean = 0,
3
- /** Computed 首屏时一定要执行 */
4
- IsEffect = 512,
5
- /** watch 节点执行 watcher 时只连接 scope */
6
- LinkScopeOnly = 256,
7
- /** 仅用于 scope 节点是否 abort */
8
- ScopeAbort = 128,
9
- /** 仅用于 scope 节点是否 ready */
10
- ScopeReady = 64,
11
- /** 当前节点是 scope 节点 */
12
- IsScope = 32,
13
- /** 当前节点正在 pull 递归中标记为 dirty, 保证 pulling 过程中不影响 dirty 传播 */
14
- PullingNeedCompute = 16,
15
- /** 当前节点正在 pull 递归中标记为 unknown, 保证 pulling 过程中不影响 dirty 传播 */
16
- PullingUnknown = 8,
17
- /** 当前节点可能变化 */
18
- Unknown = 4,
19
- /** 节点需要重新计算 */
20
- NeedCompute = 2,
21
- /** 给正在拉取的节点上 PullLock 锁 */
22
- PullLock = 1
23
- }
24
-
25
- declare class Signal<T = any> {
26
- value: T;
27
- scope: Effect | Scope;
28
- emitHead: Link;
29
- emitTail: Link;
30
- state: State;
31
- constructor(value: T);
32
- get(shouldLink?: boolean): T;
33
- set(v: T): void;
34
- }
35
-
36
- type SignalNode = Partial<Signal & Effect & Scope & Computed>;
1
+ type OnClean = (isDestroy: boolean) => any;
2
+ type SignalNode = Partial<Omit<Computed, 'callback'> & {
3
+ dispose(): void;
4
+ }>;
37
5
  type Link = {
38
6
  execId: number;
39
7
  up: SignalNode;
@@ -50,7 +18,7 @@ type OutLink = Link & {
50
18
  type SideEffect = Effect | Computed;
51
19
 
52
20
  declare class Scope {
53
- callback: () => any;
21
+ callback: () => OnClean | any;
54
22
  emitHead: Link;
55
23
  emitTail: Link;
56
24
  recHead: Link;
@@ -58,8 +26,8 @@ declare class Scope {
58
26
  state: number;
59
27
  scope: Effect | Scope;
60
28
  outLink: OutLink;
61
- clean?: () => void;
62
- constructor(callback: () => any);
29
+ clean: OnClean;
30
+ constructor(callback: () => OnClean | any);
63
31
  get(shouldLink?: boolean): void;
64
32
  }
65
33
  interface Scope {
@@ -67,7 +35,7 @@ interface Scope {
67
35
  }
68
36
 
69
37
  declare class Effect {
70
- callback: (thisArg: SignalNode) => any;
38
+ callback: (thisArg: Effect) => OnClean | void;
71
39
  emitHead: Link;
72
40
  emitTail: Link;
73
41
  recHead: Link;
@@ -75,16 +43,40 @@ declare class Effect {
75
43
  state: number;
76
44
  scope: Effect | Scope;
77
45
  outLink: OutLink;
78
- clean: () => void;
79
- constructor(callback: (thisArg: SignalNode) => any);
46
+ clean: OnClean;
47
+ constructor(callback: (thisArg: Effect) => OnClean | void);
80
48
  get(shouldLink?: boolean, notForceUpdate?: boolean): void;
81
49
  }
82
50
  interface Effect {
83
51
  dispose(): void;
84
52
  }
85
53
 
54
+ declare const enum State {
55
+ Clean = 0,
56
+ /** Computed 首屏时一定要执行 */
57
+ IsEffect = 512,
58
+ /** watch 节点执行 watcher 时只连接 scope */
59
+ LinkScopeOnly = 256,
60
+ /** 仅用于 scope 节点是否 abort */
61
+ ScopeAbort = 128,
62
+ /** 仅用于 scope 节点是否 ready */
63
+ ScopeReady = 64,
64
+ /** 当前节点是 scope 节点 */
65
+ IsScope = 32,
66
+ /** 当前节点正在 pull 递归中标记为 dirty, 保证 pulling 过程中不影响 dirty 传播 */
67
+ PullingNeedCompute = 16,
68
+ /** 当前节点正在 pull 递归中标记为 unknown, 保证 pulling 过程中不影响 dirty 传播 */
69
+ PullingUnknown = 8,
70
+ /** 当前节点可能变化 */
71
+ Unknown = 4,
72
+ /** 节点需要重新计算 */
73
+ NeedCompute = 2,
74
+ /** 给正在拉取的节点上 PullLock 锁 */
75
+ PullLock = 1
76
+ }
77
+
86
78
  declare class Computed<T = any> {
87
- callback: (thisArgs: SignalNode) => T;
79
+ callback: (thisArgs: Computed) => T;
88
80
  emitHead: Link;
89
81
  emitTail: Link;
90
82
  recHead: Link;
@@ -92,13 +84,24 @@ declare class Computed<T = any> {
92
84
  state: State;
93
85
  scope: Effect | Scope;
94
86
  value: T;
95
- constructor(callback: (thisArgs: SignalNode) => T);
87
+ constructor(callback: (thisArgs: Computed) => T);
96
88
  get(shouldLink?: boolean, notForceUpdate?: boolean): T;
97
89
  }
98
90
 
91
+ declare class Signal<T = any> {
92
+ value: T;
93
+ scope: Effect | Scope;
94
+ emitHead: Link;
95
+ emitTail: Link;
96
+ state: State;
97
+ constructor(value: T);
98
+ get(shouldLink?: boolean): T;
99
+ set(v: T): void;
100
+ }
101
+
99
102
  declare const batchStart: () => number;
100
103
  declare const batchEnd: () => void;
101
- declare function clean(onClean: () => any): void;
104
+ declare function clean(onClean: OnClean): void;
102
105
 
103
106
  declare const execIdInc: () => number;
104
107
  /** effect、computed 回调执行的唯一 id
@@ -106,7 +109,9 @@ declare const execIdInc: () => number;
106
109
  */
107
110
  declare const execId: () => number;
108
111
  declare const setExecId: (v: number) => number;
109
- declare const setPulling: (v: SignalNode) => any;
112
+ declare const setPulling: (v: SignalNode) => Partial<Omit<Computed<any>, "callback"> & {
113
+ dispose(): void;
114
+ }>;
110
115
  declare const getPulling: () => any;
111
116
  declare function runWithPulling<T extends (...args: any[]) => any>(fn: T, scope: any): ReturnType<T>;
112
117
 
@@ -187,8 +192,8 @@ declare const DefaultCustomEffectOpt: {
187
192
  };
188
193
  type CustomEffectOpt = Partial<typeof DefaultCustomEffectOpt>;
189
194
  declare function effectUt(callback: (...args: ValueDiff[]) => void, depOrOpt?: any[] | CustomEffectOpt, opt?: CustomEffectOpt): any;
190
- declare function effect(callback: (...args: ValueDiff[]) => void, depOrOpt?: any[] | CustomEffectOpt, opt?: CustomEffectOpt): any;
195
+ declare function effect(callback: (...args: ValueDiff[]) => void, depOrOpt?: any[] | CustomEffectOpt, opt?: CustomEffectOpt): Effect;
191
196
  declare function scope(...args: any[]): any;
192
197
 
193
198
  export { $, Computed, Effect, IsStore, Keys, Scope, Signal, Store, StoreIgnoreKeys, batchEnd, batchStart, clean, deepSignal, effect, effectUt, execId, execIdInc, getPulling, ide, macro, micro, now, runWithPulling, scope, setExecId, setPulling, shareSignal, toRaw };
194
- export type { CreateScope, CreateTaskProps, CustomEffectOpt, DeepOmitPath, DeepPath, DeepValue, Dispose, Key, Link, MatchValue, Mix, OutLink, PRecord, SideEffect, SignalNode, SignalType, Task, TaskControlReturn, ValueDiff };
199
+ export type { CreateScope, CreateTaskProps, CustomEffectOpt, DeepOmitPath, DeepPath, DeepValue, Dispose, Key, Link, MatchValue, Mix, OnClean, OutLink, PRecord, SideEffect, SignalNode, SignalType, Task, TaskControlReturn, ValueDiff };
package/dist/index.umd.js CHANGED
@@ -284,7 +284,7 @@
284
284
  outLink = next;
285
285
  }
286
286
  scope.state |= 128;
287
- scope.clean?.();
287
+ scope.clean?.(true);
288
288
  scope.clean = null;
289
289
  }
290
290
 
@@ -525,7 +525,7 @@
525
525
  } else {
526
526
  this.state |= 1;
527
527
  setPulling(null);
528
- this.clean?.();
528
+ this.clean?.(false);
529
529
  this.clean = null;
530
530
  const nextId = execIdInc();
531
531
  const prevId = execId();
@@ -561,6 +561,7 @@
561
561
  state = ScopeAndLinkScopeOnly;
562
562
  scope = getPulling();
563
563
  outLink = null;
564
+ clean = null;
564
565
  constructor(callback) {
565
566
  this.callback = callback;
566
567
  }
@@ -580,6 +581,15 @@
580
581
  }
581
582
  Scope.prototype.dispose = dispose;
582
583
 
584
+ let Keys = function (Keys) {
585
+ Keys["Iterator"] = "__AOYE_ITERATOR";
586
+ Keys["Raw"] = "__AOYE_RAW";
587
+ Keys["Meta"] = "__AOYE_META";
588
+ return Keys;
589
+ }({});
590
+ const IsStore = Symbol('__AOYE_IS_STORE'),
591
+ StoreIgnoreKeys = Symbol('__AOYE_IGNORE_KEYS');
592
+
583
593
  const rawToProxy = new WeakMap();
584
594
  let State = function (State) {
585
595
  State[State["Clean"] = 0] = "Clean";
@@ -598,15 +608,6 @@
598
608
  State.ScopeReady | State.ScopeAbort;
599
609
  State.ScopeAbort;
600
610
 
601
- let Keys = function (Keys) {
602
- Keys["Iterator"] = "__AOYE_ITERATOR";
603
- Keys["Raw"] = "__AOYE_RAW";
604
- Keys["Meta"] = "__AOYE_META";
605
- return Keys;
606
- }({});
607
- const IsStore = Symbol('__AOYE_IS_STORE'),
608
- StoreIgnoreKeys = Symbol('__AOYE_IGNORE_KEYS');
609
-
610
611
  const ide = globalThis.requestIdleCallback || (globalThis.requestAnimationFrame ? fn => globalThis.requestAnimationFrame(() => {
611
612
  setTimeout(() => {
612
613
  fn();
@@ -691,6 +692,7 @@
691
692
  }
692
693
  const wrappedValue = deep ? deepSignal(value, scope) : value;
693
694
  s = new Signal(wrappedValue);
695
+ s.scope = scope;
694
696
  cells.set(prop, s);
695
697
  return s.get();
696
698
  },
@@ -1210,9 +1212,7 @@
1210
1212
  opt = hasDep ? opt || {} : depOrOpt || {};
1211
1213
  if (!hasDep) {
1212
1214
  const ef = new Effect(callback);
1213
- const run = ef.dispose.bind(ef);
1214
- run.ins = ef;
1215
- return run;
1215
+ return ef;
1216
1216
  }
1217
1217
  let mounted = false;
1218
1218
  const deps = depOrOpt;
@@ -1236,9 +1236,7 @@
1236
1236
  }
1237
1237
  mounted = true;
1238
1238
  });
1239
- const run = ef.dispose.bind(ef);
1240
- run.ins = ef;
1241
- return run;
1239
+ return ef;
1242
1240
  }
1243
1241
  function scope(...args) {
1244
1242
  const ins = new Scope(args[0]);