aoye 0.0.22 → 0.0.24

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,7 +1,7 @@
1
- import { Queue, QueueItem, SubQueue } from 'bobe-shared';
2
-
3
- declare enum State {
1
+ declare const enum State {
4
2
  Clean = 0,
3
+ /** Computed 首屏时一定要执行 */
4
+ IsEffect = 512,
5
5
  /** watch 节点执行 watcher 时只连接 scope */
6
6
  LinkScopeOnly = 256,
7
7
  /** 仅用于 scope 节点是否 abort */
@@ -11,50 +11,105 @@ declare enum State {
11
11
  /** 当前节点是 scope 节点 */
12
12
  IsScope = 32,
13
13
  /** 当前节点正在 pull 递归中标记为 dirty, 保证 pulling 过程中不影响 dirty 传播 */
14
- PullingDirty = 16,
14
+ PullingNeedCompute = 16,
15
15
  /** 当前节点正在 pull 递归中标记为 unknown, 保证 pulling 过程中不影响 dirty 传播 */
16
16
  PullingUnknown = 8,
17
17
  /** 当前节点可能变化 */
18
18
  Unknown = 4,
19
- /** 当前节点有变化 */
20
- Dirty = 2,
21
- /** 当前节点正在进行 pull 预检处理 */
22
- Pulling = 1
19
+ /** 节点需要重新计算 */
20
+ NeedCompute = 2,
21
+ /** 给正在拉取的节点上 PullLock */
22
+ PullLock = 1
23
23
  }
24
24
 
25
- declare class Line {
26
- static link(v1: Signal, v2: Signal): void;
27
- static unlink(line: Line): void;
28
- static unlinkRec(line: Line): void;
29
- static unlinkEmit(line: Line): void;
30
- /** 上游节点 连 link */
31
- static emit_line(upstream: Signal, line: Line): void;
32
- /** 下游节点 连 link */
33
- static rec_line(downstream: Signal, line: Line): void;
34
- /** 同一节点发出的 两个条线 相连 */
35
- static line_line_emit(l1: Line, l2: Line): void;
36
- /** 同一节点接收的 两个条线 相连 */
37
- static line_line_rec(l1: Line, l2: Line): void;
38
- static insert_line_emit(l1: Line, l2: Line, ins: Line): void;
39
- static insert_line_rec(l1: Line, l2: Line, ins: Line): void;
40
- /** 上游顶点 */
41
- upstream: Signal;
42
- /** 上游节点 发出的上一条线 */
43
- prevEmitLine: Line;
44
- /** 上游节点 发出的下一条线 */
45
- nextEmitLine: Line;
46
- /** 下游顶点 */
47
- downstream: Signal;
48
- /** 下游节点 接收的上一条线 */
49
- prevRecLine: Line;
50
- /** 下游节点 接收的下一条线 */
51
- nextRecLine: Line;
52
- /** 表示 scope 当前存在的 外部 link */
53
- prevOutLink: any;
54
- nextOutLink: any;
55
- constructor();
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>;
37
+ type Link = {
38
+ execId: number;
39
+ up: SignalNode;
40
+ down: SignalNode;
41
+ nextEmitLine: Link;
42
+ prevEmitLine: Link;
43
+ nextRecLine: Link;
44
+ prevRecLine: Link;
45
+ };
46
+ type OutLink = Link & {
47
+ nextOutLink: OutLink;
48
+ prevOutLink: OutLink;
49
+ };
50
+ type SideEffect = Effect | Computed;
51
+
52
+ declare class Scope {
53
+ callback: () => any;
54
+ emitHead: Link;
55
+ emitTail: Link;
56
+ recHead: Link;
57
+ recTail: Link;
58
+ state: number;
59
+ scope: Effect | Scope;
60
+ outLink: OutLink;
61
+ clean?: () => void;
62
+ constructor(callback: () => any);
63
+ get(shouldLink?: boolean): void;
64
+ }
65
+ interface Scope {
66
+ dispose(): void;
67
+ }
68
+
69
+ declare class Effect {
70
+ callback: (thisArg: SignalNode) => any;
71
+ emitHead: Link;
72
+ emitTail: Link;
73
+ recHead: Link;
74
+ recTail: Link;
75
+ state: number;
76
+ scope: Effect | Scope;
77
+ outLink: OutLink;
78
+ clean: () => void;
79
+ constructor(callback: (thisArg: SignalNode) => any);
80
+ get(shouldLink?: boolean, notForceUpdate?: boolean): void;
81
+ }
82
+ interface Effect {
83
+ dispose(): void;
56
84
  }
57
85
 
86
+ declare class Computed<T = any> {
87
+ callback: (thisArgs: SignalNode) => T;
88
+ emitHead: Link;
89
+ emitTail: Link;
90
+ recHead: Link;
91
+ recTail: Link;
92
+ state: State;
93
+ scope: Effect | Scope;
94
+ value: T;
95
+ constructor(callback: (thisArgs: SignalNode) => T);
96
+ get(shouldLink?: boolean, notForceUpdate?: boolean): T;
97
+ }
98
+
99
+ declare const batchStart: () => number;
100
+ declare const batchEnd: () => void;
101
+ declare function clean(onClean: () => any): void;
102
+
103
+ declare const execIdInc: () => number;
104
+ /** effect、computed 回调执行的唯一 id
105
+ * 用于判断重复依赖属于同一 effect、effect、computed
106
+ */
107
+ declare const execId: () => number;
108
+ declare const setExecId: (v: number) => number;
109
+ declare const setPulling: (v: SignalNode) => any;
110
+ declare const getPulling: () => any;
111
+ declare function runWithPulling<T extends (...args: any[]) => any>(fn: T, scope: any): ReturnType<T>;
112
+
58
113
  type SignalType = 'ref' | 'auto' | 'proxy';
59
114
  declare enum Keys {
60
115
  Iterator = "__AOYE_ITERATOR",
@@ -79,38 +134,6 @@ type CreateTaskProps = {
79
134
  callbackAble: (fn: Function) => any;
80
135
  aIsUrgent: (a: Task, b: Task) => boolean;
81
136
  };
82
- type ScheduleHandler = (effects: Queue<Signal>) => any;
83
- type SignalOpt<T> = {
84
- customPull?: () => T;
85
- scheduler?: string;
86
- isScope?: boolean;
87
- scope?: Signal;
88
- immediate?: boolean;
89
- };
90
- type Vertex = {
91
- /** 上游来的最后一条线 */
92
- recEnd: Line;
93
- recStart: Line;
94
- /** 向下游发出的最后一条线 */
95
- emitEnd: Line;
96
- emitStart: Line;
97
- };
98
- type DFSCtxBegin = {
99
- node: Signal;
100
- lineFromUp: Line;
101
- walkedLine: Line[];
102
- notGoDeep?: boolean;
103
- };
104
- type DFSCtxCompete = {
105
- node: Signal;
106
- lineToDeep: Line;
107
- walkedLine: Line[];
108
- notGoDeep?: boolean;
109
- };
110
- type Getter<T = any> = {
111
- (): T;
112
- ins?: Signal;
113
- };
114
137
  type Mix<T = any> = {
115
138
  (v: T): void;
116
139
  (): T;
@@ -135,115 +158,6 @@ type PRecord<K extends string | symbol | number, V> = Partial<Record<K, V>>;
135
158
  type DeepValue<T, P> = P extends [infer Head, ...infer Tail] ? Head extends keyof T ? Tail extends [] ? T[Head] : DeepValue<T[Head], Tail> : never : never;
136
159
  type MatchValue<V1, T2, P2> = (DeepValue<T2, P2> extends V1 ? P2 : never);
137
160
 
138
- declare class Signal<T = any> implements Vertex {
139
- nextValue: T;
140
- /** 为什么是 shallow,因为 pullDeep 会把
141
- * 上游节点 get 执行完成,让其可以直接拿到缓存值
142
- */
143
- private customPull?;
144
- version: number;
145
- id: number;
146
- state: State;
147
- /** 当前节点创建时处于的 effect 就是 scope */
148
- scope: Signal;
149
- recEnd: Line;
150
- recStart: Line;
151
- emitStart: Line;
152
- emitEnd: Line;
153
- scheduler: string;
154
- value: T;
155
- outLink: Line;
156
- static Pulling: Signal;
157
- pull: () => T;
158
- constructor(nextValue: T,
159
- /** 为什么是 shallow,因为 pullDeep 会把
160
- * 上游节点 get 执行完成,让其可以直接拿到缓存值
161
- */
162
- customPull?: () => T);
163
- static create<T>(nextValue: T, { customPull, isScope, scope, immediate, ...rest }: SignalOpt<T>): Signal<T>;
164
- DEFAULT_PULL(): T;
165
- /**
166
- * 递归拉取负责建立以来链
167
- */
168
- pullRecurse(shouldLink?: boolean): T;
169
- linkWhenPull(downstream: Signal, shouldLink: boolean): void;
170
- pullDeep(): T;
171
- get v(): T;
172
- markDownStreamsDirty(): void;
173
- set v(v: T);
174
- scheduleEffect(): void;
175
- /** 返回值为 true 表示已处理 */
176
- runIfDirty(): void;
177
- isDisabled(): number;
178
- /** 记录当前 effect 中 clean */
179
- clean: () => void;
180
- }
181
- declare function batchStart(): void;
182
- declare function batchEnd(): void;
183
-
184
- declare const deepSignal: <T>(target: T, scope: Signal, deep?: boolean) => any;
185
- /**
186
- * 将 from 响应式对象中 fromKey 对应的 Signal
187
- * 共享给 to 响应式对象的 toKey
188
- */
189
- declare const shareSignal: (from: any, fromPath: string, to: any, toPath: string) => void;
190
-
191
- declare abstract class Scheduler {
192
- static Sync: string;
193
- static Layout: string;
194
- static Micro: string;
195
- static Macro: string;
196
- effectQueue: Queue<Signal>;
197
- /** 每当 Set 或 BatchSet 开始时标记 */
198
- firstEffectItem: QueueItem<Signal>;
199
- /** 记录 Set 或 BatchSet 产生的最后一个 Effect */
200
- lastEffectItem: QueueItem<Signal>;
201
- endSet(): void;
202
- addEffect(effect: Signal): QueueItem<Signal<any>>;
203
- /**
204
- * 用户可实现
205
- * 一个 effect 加入队列后的 回调
206
- * */
207
- onEffectAdded(effect: Signal, item: QueueItem<Signal>, queue: Queue<Signal>): void;
208
- /**
209
- * 用户可实现
210
- * 一次 set 操作导致的所有 effect 加入队列后的 回调
211
- * */
212
- onOneSetEffectsAdded(subQueue: SubQueue<Signal>, queue: Queue<Signal>): void;
213
- }
214
- declare const registerScheduler: (key: string | symbol, Ctor: new () => Scheduler) => Scheduler;
215
-
216
- declare class PriorityQueue<T> {
217
- aIsUrgent: (a: T, b: T) => boolean;
218
- arr: T[];
219
- constructor(aIsUrgent: (a: T, b: T) => boolean);
220
- _add(current: T): void;
221
- add(...items: T[]): void;
222
- goUp: (arr: T[], current: T, len: number) => void;
223
- poll(): T;
224
- goDown: (arr: T[], i: number) => void;
225
- peek(): T;
226
- size(): number;
227
- logTree(): void;
228
- }
229
-
230
- /** TODO: 支持配置是否继续在同一任务中完成后续任务 */
231
- declare class TaskQueue {
232
- callbackAble: CreateTaskProps['callbackAble'];
233
- aIsUrgent: CreateTaskProps['aIsUrgent'];
234
- constructor(callbackAble: CreateTaskProps['callbackAble'], aIsUrgent: CreateTaskProps['aIsUrgent']);
235
- isScheduling: boolean;
236
- taskQueue: PriorityQueue<Task>;
237
- static create({ callbackAble, aIsUrgent }: CreateTaskProps): TaskQueue;
238
- pushTask(task: Task): void;
239
- scheduleTask(): boolean;
240
- }
241
-
242
- declare function clean(cb: () => void): void;
243
- declare function runWithPulling<T extends (...args: any[]) => any>(fn: T, signal: Signal | null): ReturnType<T>;
244
- declare function getPulling(): Signal<any>;
245
- declare function setPulling(pulling: Signal | null): void;
246
-
247
161
  declare class Store {
248
162
  static [IsStore]: boolean;
249
163
  static [StoreIgnoreKeys]: Key[];
@@ -254,42 +168,27 @@ declare class Store {
254
168
  map<P extends Store = any, O extends string = ''>(keyMap?: PRecord<keyof this, keyof Omit<P, O> | DeepOmitPath<P, O>>): void;
255
169
  }
256
170
 
171
+ declare const ide: typeof requestIdleCallback | typeof setTimeout;
172
+ declare const now: () => number;
173
+ declare const macro: (fn: any) => void;
174
+ declare const micro: (cb: () => any) => void;
257
175
  declare const toRaw: <T>(a: T) => any;
258
176
 
259
- declare const DefaultCustomSignalOpt: {
260
- /** 三种模式
261
- * 1. auto: 根据值类型自动判断 默认
262
- * 2. ref: 对任何值使用 {v: xxx} 进行包装
263
- * 3. proxy: 使用 proxy 进行包装
264
- */
265
- mode: SignalType;
266
- /** 是否深度响应式 */
267
- deep: boolean;
268
- };
177
+ declare const deepSignal: <T>(target: T, scope: Scope, deep?: boolean) => any;
178
+ /**
179
+ * from 响应式对象中 fromKey 对应的 Signal
180
+ * 共享给 to 响应式对象的 toKey
181
+ */
182
+ declare const shareSignal: (from: any, fromPath: string, to: any, toPath: string) => void;
183
+
184
+ declare function $(data: any): any;
269
185
  declare const DefaultCustomEffectOpt: {
270
- scheduler: string;
271
186
  immediate: boolean;
272
- isScope: boolean;
273
187
  };
274
- type CustomSignalOpt = Partial<typeof DefaultCustomSignalOpt>;
275
188
  type CustomEffectOpt = Partial<typeof DefaultCustomEffectOpt>;
276
- type CreateSignal = {
277
- <T extends (...args: any[]) => any>(get: T, opt?: CustomSignalOpt): Signal<ReturnType<T>>;
278
- <T extends object>(value: T, opt?: CustomSignalOpt): T;
279
- <T = any>(value: T, opt?: CustomSignalOpt): Signal<T>;
280
- };
281
- declare const $: CreateSignal;
282
- declare const effect: (customPull: (...args: ValueDiff[]) => void, depOrOpt?: Signal<any>[] | CustomEffectOpt, opt?: CustomEffectOpt) => Dispose;
283
- declare const scope: CreateScope;
284
- /**
285
- * 数据变化时,自定义 触发订阅函数的时机
286
- * @param {CustomSignalOpt} opt 配置如下:
287
- * @prop scheduler: (runIfDirty, effect) => void 执行 runIfDirty 定制触发 effect 时机
288
- * @prop scope: 用于统一释放 effect link 的作用域 默认是 defaultScope 可以全局获取
289
- */
290
- declare const customEffect: (opt?: CustomEffectOpt) => typeof effect;
291
- declare const isSignal: (value: unknown) => value is Signal;
292
- declare const isScope: (value: any) => boolean;
189
+ 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;
191
+ declare function scope(...args: any[]): any;
293
192
 
294
- export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batchEnd, batchStart, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal, toRaw };
295
- 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 };
193
+ 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 };