aoye 0.0.23 → 0.0.25

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.umd.js CHANGED
@@ -4,971 +4,654 @@
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();
8
- new bobeShared.BaseEvent();
9
- const G = {
10
- /** 原子 signal 更新次数 */
11
- version: 0,
12
- id: 0,
13
- /** scope 销毁任务序号 */
14
- scopeDisposeI: 0,
15
- PullingSignal: null,
16
- /** 表示当前处于 pull 递归中 */
17
- PullingRecurseDeep: 0
18
- };
19
- var State = /* @__PURE__ */(State2 => {
20
- State2[State2["Clean"] = 0] = "Clean";
21
- State2[State2["LinkScopeOnly"] = 256] = "LinkScopeOnly";
22
- State2[State2["ScopeAbort"] = 128] = "ScopeAbort";
23
- State2[State2["ScopeReady"] = 64] = "ScopeReady";
24
- State2[State2["IsScope"] = 32] = "IsScope";
25
- State2[State2["PullingDirty"] = 16] = "PullingDirty";
26
- State2[State2["PullingUnknown"] = 8] = "PullingUnknown";
27
- State2[State2["Unknown"] = 4] = "Unknown";
28
- State2[State2["Dirty"] = 2] = "Dirty";
29
- State2[State2["Pulling"] = 1] = "Pulling";
30
- return State2;
31
- })(State || {});
32
- const DirtyState = 4 /* Unknown */ | 2 /* Dirty */;
33
- const ScopeExecuted = 64 /* ScopeReady */ | 128 /* ScopeAbort */;
34
- const ScopeAbort = 128 /* ScopeAbort */;
7
+ let _execId = 0;
8
+ let currentExecId = 0;
9
+ const execIdInc = () => ++_execId;
10
+ const execId = () => currentExecId;
11
+ const setExecId = v => currentExecId = v;
12
+ let pulling = null;
13
+ const setPulling = v => pulling = v;
14
+ const getPulling = () => pulling;
15
+ function runWithPulling(fn, scope) {
16
+ const oldPulling = pulling;
17
+ pulling = scope;
18
+ const ret = fn();
19
+ pulling = oldPulling;
20
+ return ret;
21
+ }
35
22
 
36
- const leakI = (y, max) => y < 0 || y >= max ? null : y;
37
- const getLeft = (x, max) => leakI(x * 2 + 1, max);
38
- const getRight = (x, max) => leakI(x * 2 + 2, max);
39
- const getParent = (x, max) => leakI(x - 1 >>> 1, max);
40
- const exchange = (arr, i, j) => {
41
- var _ref = [arr[j], arr[i]];
42
- arr[i] = _ref[0];
43
- arr[j] = _ref[1];
44
- return _ref;
45
- };
46
- class PriorityQueue {
47
- // 构造函数接受一个compare函数
48
- // compare返回的-1, 0, 1决定元素是否优先被去除
49
- constructor(aIsUrgent) {
50
- this.aIsUrgent = aIsUrgent;
51
- this.arr = [];
52
- this.goUp = (arr, current, len) => {
53
- let i = len - 1;
54
- while (i > 0) {
55
- const item = arr[i];
56
- const pI = getParent(i, len);
57
- const parent = arr[pI];
58
- if (this.aIsUrgent(item, parent)) {
59
- exchange(arr, i, pI);
60
- i = pI;
61
- } else {
62
- break;
23
+ function mark(signal) {
24
+ let line = signal.emitHead;
25
+ while (line) {
26
+ const _line = line,
27
+ down = _line.down;
28
+ _line.up;
29
+ const scope = down.scope,
30
+ emitHead = down.emitHead,
31
+ state = down.state;
32
+ if (scope && scope.state & 128) ; else {
33
+ const notLocked = (state & 1) === 0;
34
+ down.state |= notLocked ? 2 : 16;
35
+ if (state & 32) {
36
+ if (notLocked && state & 512) {
37
+ addEffect(down);
63
38
  }
39
+ } else if (emitHead) {
40
+ markUnknownDeep(emitHead);
64
41
  }
65
- };
66
- this.goDown = (arr, i) => {
67
- const len = this.size();
68
- const half = len >>> 1;
69
- while (i < half) {
70
- const lI = getLeft(i, len);
71
- const rI = getRight(i, len);
72
- let point = i;
73
- if (lI != null && this.aIsUrgent(arr[lI], arr[point])) {
74
- point = lI;
75
- }
76
- if (rI != null && this.aIsUrgent(arr[rI], arr[point])) {
77
- point = rI;
78
- }
79
- if (point === i) {
80
- break;
42
+ }
43
+ line = line.nextEmitLine;
44
+ }
45
+ }
46
+ function markUnknownDeep(initialLine) {
47
+ const noPulling = !getPulling();
48
+ const stack = [initialLine];
49
+ let len = 1;
50
+ while (len > 0) {
51
+ let line = stack[--len];
52
+ stack[len] = null;
53
+ while (line) {
54
+ const _line2 = line,
55
+ down = _line2.down;
56
+ _line2.up;
57
+ const state = down.state,
58
+ scope = down.scope;
59
+ if (scope && scope.state & 128 || noPulling && state & 6) ; else {
60
+ const notLocked = (state & 1) === 0;
61
+ down.state |= notLocked ? 4 : 8;
62
+ if (state & 32) {
63
+ if (notLocked && state & 512) {
64
+ addEffect(down);
65
+ }
66
+ } else if (down.emitHead) {
67
+ stack[len++] = down.emitHead;
81
68
  }
82
- exchange(arr, i, point);
83
- i = point;
84
69
  }
85
- };
86
- }
87
- // 添加一个元素
88
- _add(current) {
89
- this.arr.push(current);
90
- const len = this.size();
91
- if (len === 1) {
92
- return;
70
+ line = line.nextEmitLine;
93
71
  }
94
- this.goUp(this.arr, current, len);
95
72
  }
96
- add(...items) {
97
- items.forEach(it => this._add(it));
98
- }
99
- // 去除头元素并返回
100
- poll() {
101
- const arr = this.arr;
102
- const len = this.size();
103
- if (len <= 2) {
104
- return arr.shift();
73
+ }
74
+ function pullDeep(root) {
75
+ let node = root,
76
+ top = null,
77
+ i = -1;
78
+ const lineStack = [];
79
+ do {
80
+ const _node = node,
81
+ state = _node.state,
82
+ scope = _node.scope;
83
+ let noSkipSelf = !(state & 193 || (state & 6) === 0 || scope && scope.state & 128);
84
+ const firstLine = node.recHead;
85
+ if (noSkipSelf) {
86
+ node.state |= 1;
87
+ if ((state & 2) === 0 && firstLine) {
88
+ node = firstLine.up;
89
+ lineStack[++i] = top;
90
+ top = firstLine;
91
+ continue;
92
+ }
105
93
  }
106
- const last = arr.pop();
107
- const first = arr[0];
108
- arr[0] = last;
109
- this.goDown(this.arr, 0);
110
- return first;
111
- }
112
- // 取得头元素
113
- peek() {
114
- return this.arr[0];
115
- }
116
- // 取得元素数量
117
- size() {
118
- return this.arr.length;
119
- }
120
- logTree() {
121
- const arr = this.arr;
122
- let i = 0;
123
- let j = 1;
124
- let level = 0;
125
- const matrix = [];
126
94
  do {
127
- matrix.push(arr.slice(i, j));
128
- i = i * 2 + 1;
129
- j = i + Math.pow(2, level) + 1;
130
- level++;
131
- } while (i < arr.length);
132
- const last = Math.pow(2, matrix.length - 1);
133
- const arrStr = JSON.stringify(last);
134
- const halfLen = arrStr.length >>> 1;
135
- matrix.forEach(it => {
136
- const str = JSON.stringify(it);
137
- const halfIt = str.length >>> 1;
138
- console.log(str.padStart(halfLen + halfIt, " "));
139
- });
140
- console.log("\n");
141
- }
95
+ const _node2 = node,
96
+ state = _node2.state;
97
+ let noGoSibling = false;
98
+ if (noSkipSelf) {
99
+ if (state & 2) {
100
+ const prevValue = node.value;
101
+ const prevPulling = getPulling();
102
+ setPulling(node);
103
+ const value = node.get(false, false);
104
+ setPulling(prevPulling);
105
+ if (noGoSibling = value !== prevValue) {
106
+ let line = node.emitHead;
107
+ while (line) {
108
+ const _line3 = line,
109
+ down = _line3.down;
110
+ down.state &= -5;
111
+ down.state |= 2;
112
+ line = line.nextEmitLine;
113
+ }
114
+ }
115
+ } else {
116
+ transferDirtyState(node, state);
117
+ }
118
+ node.state &= -2;
119
+ }
120
+ if (node === root) {
121
+ return node.value;
122
+ }
123
+ if (!noGoSibling && top.nextRecLine) {
124
+ top = top.nextRecLine;
125
+ node = top.up;
126
+ break;
127
+ }
128
+ noSkipSelf = true;
129
+ node = top.down;
130
+ top = lineStack[i];
131
+ lineStack[i--] = null;
132
+ } while (true);
133
+ } while (true);
142
134
  }
143
-
144
- const DefaultTaskControlReturn = {
145
- finished: true,
146
- startNewCallbackAble: true
147
- };
148
- class TaskQueue {
149
- constructor(callbackAble, aIsUrgent) {
150
- this.callbackAble = callbackAble;
151
- this.aIsUrgent = aIsUrgent;
152
- this.isScheduling = false;
153
- }
154
- static create({
155
- callbackAble,
156
- aIsUrgent
157
- }) {
158
- const queue = new TaskQueue(callbackAble, aIsUrgent);
159
- queue.taskQueue = new PriorityQueue(aIsUrgent);
160
- return queue;
161
- }
162
- pushTask(task) {
163
- const taskQueue = this.taskQueue,
164
- isScheduling = this.isScheduling;
165
- taskQueue._add(task);
166
- if (!isScheduling) {
167
- this.callbackAble(this.scheduleTask.bind(this));
168
- this.isScheduling = true;
169
- }
135
+ function transferDirtyState(node, state) {
136
+ if (state & 8) {
137
+ node.state = state & -9 | 4;
138
+ } else {
139
+ node.state &= -5;
170
140
  }
171
- scheduleTask() {
172
- const taskQueue = this.taskQueue;
173
- const fn = taskQueue.peek();
174
- if (!fn) return this.isScheduling = false;
175
- let info = fn() || {};
176
- info = {
177
- ...DefaultTaskControlReturn,
178
- ...info
179
- };
180
- if (info.finished) {
181
- taskQueue.poll();
182
- if (taskQueue.size() === 0) {
183
- return this.isScheduling = false;
184
- }
185
- }
186
- if (info.startNewCallbackAble) {
187
- this.callbackAble(this.scheduleTask.bind(this));
188
- } else {
189
- this.scheduleTask();
190
- }
141
+ if (state & 16) {
142
+ node.state = state & -17 | 2;
143
+ } else {
144
+ node.state &= -3;
191
145
  }
192
146
  }
193
-
194
- var Keys = /* @__PURE__ */(Keys2 => {
195
- Keys2["Iterator"] = "__AOYE_ITERATOR";
196
- Keys2["Raw"] = "__AOYE_RAW";
197
- Keys2["Meta"] = "__AOYE_META";
198
- return Keys2;
199
- })(Keys || {});
200
- const IsStore = /* @__PURE__ */Symbol("__AOYE_IS_STORE"),
201
- StoreIgnoreKeys = /* @__PURE__ */Symbol("__AOYE_IGNORE_KEYS");
202
-
203
- let channel = globalThis.MessageChannel ? new MessageChannel() : null;
204
- if (globalThis.MessageChannel) {
205
- channel = new MessageChannel();
147
+ const effectQueue = [];
148
+ let consumeI = -1,
149
+ produceI = -1;
150
+ function addEffect(effect) {
151
+ effectQueue[++produceI] = effect;
206
152
  }
207
- let msgId = 0;
208
- const macro = fn => {
209
- if (!channel) {
210
- setTimeout(fn);
153
+ function flushEffect() {
154
+ if (consumeI !== -1) {
155
+ return;
211
156
  }
212
- const memoId = msgId;
213
- function onMessage(e) {
214
- if (memoId === e.data) {
215
- fn();
216
- channel.port2.removeEventListener("message", onMessage);
157
+ while (++consumeI <= produceI) {
158
+ const effect = effectQueue[consumeI];
159
+ if (effect.state | 6) {
160
+ effect.get();
217
161
  }
162
+ effectQueue[consumeI] = null;
218
163
  }
219
- channel.port2.addEventListener("message", onMessage);
220
- channel.port1.postMessage(msgId++);
221
- };
222
- const p = Promise.resolve();
223
- const micro = cb => {
224
- p.then(cb);
225
- };
226
- const toRaw = a => {
227
- if (typeof a === "object" && a !== null && a[Keys.Raw]) {
228
- return toRaw(a[Keys.Raw]);
164
+ consumeI = -1;
165
+ produceI = -1;
166
+ }
167
+ let _batchDeep = 0;
168
+ const batchStart = () => _batchDeep++;
169
+ const batchEnd = () => {
170
+ _batchDeep--;
171
+ if (_batchDeep === 0) {
172
+ flushEffect();
229
173
  }
230
- return a;
231
174
  };
232
-
233
- class Scheduler {
234
- constructor() {
235
- this.effectQueue = new bobeShared.Queue();
236
- /** 每当 Set 或 BatchSet 开始时标记 */
237
- this.firstEffectItem = null;
238
- /** 记录 Set 或 BatchSet 产生的最后一个 Effect */
239
- this.lastEffectItem = null;
240
- }
241
- static {
242
- this.Sync = "__Sync_";
243
- }
244
- static {
245
- this.Layout = "__Layout_";
246
- }
247
- static {
248
- this.Micro = "__Micro_";
249
- }
250
- static {
251
- this.Macro = "__Macro_";
175
+ const batchDeep = () => _batchDeep;
176
+ function unlink(line, deep) {
177
+ const nextEmitLine = line.nextEmitLine,
178
+ prevEmitLine = line.prevEmitLine,
179
+ nextRecLine = line.nextRecLine,
180
+ prevRecLine = line.prevRecLine,
181
+ up = line.up,
182
+ down = line.down,
183
+ prevOutLink = line.prevOutLink,
184
+ nextOutLink = line.nextOutLink;
185
+ const scope = down.scope;
186
+ if (prevEmitLine) {
187
+ prevEmitLine.nextEmitLine = nextEmitLine;
188
+ } else {
189
+ up.emitHead = nextEmitLine;
252
190
  }
253
- endSet() {
254
- if (!this.firstEffectItem) return;
255
- const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
256
- this.firstEffectItem = null;
257
- this.lastEffectItem = null;
258
- this.onOneSetEffectsAdded?.(subQueue, this.effectQueue);
191
+ if (nextEmitLine) {
192
+ nextEmitLine.prevEmitLine = prevEmitLine;
193
+ } else {
194
+ up.emitTail = prevEmitLine;
259
195
  }
260
- addEffect(effect) {
261
- const item = this.effectQueue.push(effect);
262
- this.onEffectAdded?.(effect, item, this.effectQueue);
263
- return item;
196
+ if (prevRecLine) {
197
+ prevRecLine.nextRecLine = nextRecLine;
198
+ } else {
199
+ down.recHead = nextRecLine;
264
200
  }
265
- }
266
- class SyncScheduler extends Scheduler {
267
- onOneSetEffectsAdded(subQueue, queue) {
268
- subQueue.forEach((effect, item) => {
269
- queue.delete(item);
270
- effect.runIfDirty();
271
- });
201
+ if (nextRecLine) {
202
+ nextRecLine.prevRecLine = prevRecLine;
203
+ } else {
204
+ down.recTail = prevRecLine;
205
+ }
206
+ if (prevOutLink) {
207
+ prevOutLink.nextOutLink = nextOutLink;
208
+ }
209
+ if (nextOutLink) {
210
+ nextOutLink.prevOutLink = prevOutLink;
211
+ }
212
+ if (scope && scope.outLink === line) {
213
+ scope.outLink = nextOutLink;
214
+ }
215
+ if (up.state & 32) {
216
+ up.dispose();
217
+ } else if (deep && !prevEmitLine && !nextEmitLine) {
218
+ let _ref = up,
219
+ line = _ref.recHead;
220
+ while (line) {
221
+ const next = line.nextRecLine;
222
+ unlink(line, true);
223
+ line = next;
224
+ }
272
225
  }
273
226
  }
274
- class MicroScheduler extends Scheduler {
275
- constructor() {
276
- super(...arguments);
277
- this.taskQueue = TaskQueue.create({
278
- callbackAble: micro,
279
- aIsUrgent: (a, b) => a.time < b.time
280
- });
281
- }
282
- onOneSetEffectsAdded(subQueue, queue) {
283
- const task = () => {
284
- subQueue.forEach((effect, item) => {
285
- queue.delete(item);
286
- effect.runIfDirty();
287
- });
288
- return {
289
- finished: true,
290
- startNewCallbackAble: false
291
- };
292
- };
293
- task.time = Date.now();
294
- this.taskQueue.pushTask(task);
227
+ function dispose() {
228
+ let toDel = this.recHead,
229
+ emitHead = this.emitHead;
230
+ while (toDel) {
231
+ const _toDel = toDel,
232
+ up = _toDel.up,
233
+ nextRecLine = _toDel.nextRecLine;
234
+ if ((up.state & 32) === 0) {
235
+ unlink(toDel, true);
236
+ toDel = nextRecLine;
237
+ continue;
238
+ }
239
+ let node = up,
240
+ top = null,
241
+ i = -1;
242
+ const lineStack = [];
243
+ outer: do {
244
+ let noSkipSelf = node.state & 32 && (node.state & 128) === 0;
245
+ const firstLine = node.recHead;
246
+ if (noSkipSelf && firstLine) {
247
+ node = firstLine.up;
248
+ lineStack[++i] = top;
249
+ top = firstLine;
250
+ continue;
251
+ }
252
+ do {
253
+ if (noSkipSelf) {
254
+ releaseScope(node);
255
+ }
256
+ if (node === up) {
257
+ break outer;
258
+ }
259
+ if (top.nextRecLine) {
260
+ top = top.nextRecLine;
261
+ node = top.up;
262
+ break;
263
+ }
264
+ noSkipSelf = true;
265
+ node = top.down;
266
+ top = lineStack[i];
267
+ lineStack[i--] = null;
268
+ } while (true);
269
+ } while (true);
270
+ toDel = nextRecLine;
295
271
  }
272
+ releaseScope(this);
273
+ if (emitHead) unlink(emitHead, false);
296
274
  }
297
- class MacroScheduler extends Scheduler {
298
- constructor() {
299
- super(...arguments);
300
- this.taskQueue = TaskQueue.create({
301
- callbackAble: macro,
302
- aIsUrgent: (a, b) => a.time < b.time
303
- });
304
- }
305
- onOneSetEffectsAdded(subQueue, queue) {
306
- const task = () => {
307
- subQueue.forEach((effect, item) => {
308
- queue.delete(item);
309
- effect.runIfDirty();
310
- });
311
- };
312
- task.time = Date.now();
313
- this.taskQueue.pushTask(task);
314
- }
275
+ function clean(onClean) {
276
+ const current = getPulling();
277
+ current.clean = onClean;
315
278
  }
316
- class LayoutScheduler extends Scheduler {
317
- constructor() {
318
- super(...arguments);
319
- this.taskQueue = TaskQueue.create({
320
- callbackAble: macro,
321
- aIsUrgent: (a, b) => a.time < b.time
322
- });
323
- }
324
- onOneSetEffectsAdded(subQueue, queue) {
325
- const task = () => {
326
- subQueue.forEach((effect, item) => {
327
- queue.delete(item);
328
- effect.runIfDirty();
329
- });
330
- };
331
- task.time = Date.now();
332
- this.taskQueue.pushTask(task);
279
+ function releaseScope(scope) {
280
+ let outLink = scope.outLink;
281
+ while (outLink) {
282
+ const next = outLink.nextOutLink;
283
+ unlink(outLink, true);
284
+ outLink = next;
333
285
  }
286
+ scope.state |= 128;
287
+ scope.clean?.();
288
+ scope.clean = null;
334
289
  }
335
- const _scheduler = {
336
- [Scheduler.Sync]: new SyncScheduler(),
337
- [Scheduler.Micro]: new MicroScheduler(),
338
- [Scheduler.Macro]: new MacroScheduler(),
339
- [Scheduler.Layout]: new LayoutScheduler()
340
- };
341
- globalThis["sche"] = _scheduler[Scheduler.Sync];
342
- const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
343
290
 
344
- class Line {
345
- constructor() {
346
- /** 上游顶点 */
347
- this.upstream = null;
348
- /** 上游节点 发出的上一条线 */
349
- this.prevEmitLine = null;
350
- /** 上游节点 发出的下一条线 */
351
- this.nextEmitLine = null;
352
- /** 下游顶点 */
353
- this.downstream = null;
354
- /** 下游节点 接收的上一条线 */
355
- this.prevRecLine = null;
356
- /** 下游节点 接收的下一条线 */
357
- this.nextRecLine = null;
358
- /** 表示 scope 当前存在的 外部 link */
359
- this.prevOutLink = null;
360
- this.nextOutLink = null;
361
- }
362
- static link(v1, v2) {
363
- let emitEnd = v1.emitEnd,
364
- recEnd = v2.recEnd,
365
- recStart = v2.recStart,
366
- noRecEnd = !recEnd,
367
- head = {
368
- nextRecLine: recStart
369
- },
370
- line;
371
- recEnd = recEnd || head;
372
- const _ref = recEnd || {},
373
- nextRecLine = _ref.nextRecLine;
374
- if (!nextRecLine) {
375
- line = new Line();
376
- Line.emit_line(v1, line);
377
- Line.rec_line(v2, line);
378
- emitEnd && Line.line_line_emit(emitEnd, line);
379
- !noRecEnd && Line.line_line_rec(recEnd, line);
380
- } else if (nextRecLine.upstream === v1) {
381
- v2.recEnd = nextRecLine;
382
- } else {
383
- line = new Line();
384
- Line.emit_line(v1, line);
385
- Line.rec_line(v2, line);
386
- emitEnd && Line.line_line_emit(emitEnd, line);
387
- Line.insert_line_rec(recEnd, nextRecLine, line);
388
- }
389
- for (const key in head) {
390
- head[key] = null;
391
- }
392
- if (line && v2.scope && v1.scope !== v2.scope && (v1.state & State.IsScope) === 0) {
393
- const first = v2.scope.outLink;
394
- if (!first) {
395
- v2.scope.outLink = line;
396
- } else {
397
- first.prevOutLink = line;
398
- line.nextOutLink = first;
399
- v2.scope.outLink = line;
400
- }
401
- }
291
+ function link(up = null, down = null) {
292
+ const prevEmitLine = up.emitTail,
293
+ scopeUp = up.scope;
294
+ let recHead = down.recHead,
295
+ recTail = down.recTail,
296
+ scopeDown = down.scope;
297
+ if (scopeDown && scopeDown !== scopeUp && (up.state & 32) === 0) {
298
+ outLink(up, down);
299
+ return;
402
300
  }
403
- static unlink(line) {
404
- let prevEmitLine = line.prevEmitLine,
405
- nextEmitLine = line.nextEmitLine,
406
- prevRecLine = line.prevRecLine,
407
- nextRecLine = line.nextRecLine,
408
- upstream = line.upstream,
409
- downstream = line.downstream,
410
- nextOutLink = line.nextOutLink,
411
- prevOutLink = line.prevOutLink;
412
- line.prevEmitLine = null;
413
- line.nextEmitLine = null;
414
- line.prevRecLine = null;
415
- line.nextRecLine = null;
416
- line.upstream = null;
417
- line.downstream = null;
418
- line.prevOutLink = null;
419
- line.nextOutLink = null;
420
- const downNode = downstream;
421
- if (prevOutLink) {
422
- prevOutLink.nextOutLink = nextOutLink;
423
- }
424
- if (nextOutLink) {
425
- nextOutLink.prevOutLink = prevOutLink;
426
- }
427
- if (downNode.scope && downNode.scope.outLink === line) {
428
- downNode.scope.outLink = nextOutLink;
429
- }
301
+ const nextRec = recTail ? recTail.nextRecLine : recHead;
302
+ const eid = execId();
303
+ if (prevEmitLine && prevEmitLine.down === down && prevEmitLine.execId === eid) {
304
+ return;
305
+ }
306
+ if (!nextRec) {
307
+ const line = {
308
+ execId: eid,
309
+ up,
310
+ down,
311
+ prevEmitLine,
312
+ nextEmitLine: null,
313
+ prevRecLine: recTail,
314
+ nextRecLine: null
315
+ };
430
316
  if (prevEmitLine) {
431
- prevEmitLine.nextEmitLine = nextEmitLine;
432
- } else {
433
- upstream.emitStart = nextEmitLine;
434
- }
435
- if (nextEmitLine) {
436
- nextEmitLine.prevEmitLine = prevEmitLine;
317
+ prevEmitLine.nextEmitLine = line;
437
318
  } else {
438
- upstream.emitEnd = prevEmitLine;
319
+ up.emitHead = line;
439
320
  }
440
- if (prevRecLine) {
441
- prevRecLine.nextRecLine = nextRecLine;
321
+ up.emitTail = line;
322
+ if (recTail) {
323
+ recTail.nextRecLine = line;
442
324
  } else {
443
- downstream.recStart = nextRecLine;
325
+ down.recHead = line;
444
326
  }
445
- if (nextRecLine) {
446
- nextRecLine.prevRecLine = prevRecLine;
447
- } else {
448
- downstream.recEnd = prevRecLine;
449
- }
450
- }
451
- static unlinkRec(line) {
452
- let toDel = line;
453
- while (toDel) {
454
- const memoNext = toDel.nextRecLine;
455
- Line.unlink(toDel);
456
- toDel = memoNext;
457
- }
458
- }
459
- static unlinkEmit(line) {
460
- let toDel = line;
461
- while (toDel) {
462
- const memoNext = toDel.nextEmitLine;
463
- Line.unlink(toDel);
464
- toDel = memoNext;
465
- }
466
- }
467
- /** 上游节点 连 link */
468
- static emit_line(upstream, line) {
469
- if (!upstream.emitStart) {
470
- upstream.emitStart = line;
471
- }
472
- upstream.emitEnd = line;
473
- line.upstream = upstream;
327
+ down.recTail = line;
328
+ return;
474
329
  }
475
- /** 下游节点 link */
476
- static rec_line(downstream, line) {
477
- if (!downstream.recStart) {
478
- downstream.recStart = line;
479
- }
480
- downstream.recEnd = line;
481
- line.downstream = downstream;
482
- }
483
- /** 同一节点发出的 两个条线 相连 */
484
- static line_line_emit(l1, l2) {
485
- if (!l1 || !l2) return;
486
- l1.nextEmitLine = l2;
487
- l2.prevEmitLine = l1;
488
- }
489
- /** 同一节点接收的 两个条线 相连 */
490
- static line_line_rec(l1, l2) {
491
- if (!l1 || !l2) return;
492
- l1.nextRecLine = l2;
493
- l2.prevRecLine = l1;
494
- }
495
- static insert_line_emit(l1, l2, ins) {
496
- l1.nextEmitLine = ins;
497
- ins.prevEmitLine = l1;
498
- l2.prevEmitLine = ins;
499
- ins.nextEmitLine = l2;
500
- }
501
- static insert_line_rec(l1, l2, ins) {
502
- l1.nextRecLine = ins;
503
- ins.prevRecLine = l1;
504
- l2.prevRecLine = ins;
505
- ins.nextRecLine = l2;
330
+ if (nextRec.up === up) {
331
+ nextRec.execId = eid;
332
+ down.recTail = nextRec;
333
+ return;
506
334
  }
507
- }
508
-
509
- function unlinkRecWithScope(line) {
510
- let toDel = line;
511
- while (toDel) {
512
- const memoNext = toDel.nextRecLine;
513
- const upstream = toDel.upstream;
514
- if (upstream.state & State.IsScope) {
515
- dispose.call(upstream);
516
- } else {
517
- unlinkSingleLine(toDel);
518
- }
519
- toDel = memoNext;
335
+ const line = {
336
+ execId: eid,
337
+ up,
338
+ down,
339
+ prevEmitLine,
340
+ nextEmitLine: null,
341
+ prevRecLine: recTail,
342
+ nextRecLine: nextRec
343
+ };
344
+ if (prevEmitLine) {
345
+ prevEmitLine.nextEmitLine = line;
346
+ } else {
347
+ up.emitHead = line;
520
348
  }
521
- }
522
- function unlinkSingleLine(line) {
523
- const upstream = line.upstream;
524
- if (upstream.emitStart === upstream.emitEnd) {
525
- unlinkSingleRefedNode(upstream);
349
+ up.emitTail = line;
350
+ if (recHead) {
351
+ recTail.nextRecLine = line;
526
352
  } else {
527
- Line.unlink(line);
353
+ down.recHead = line;
528
354
  }
355
+ down.recTail = line;
356
+ if (recTail) recTail.nextRecLine = line;
357
+ nextRec.prevRecLine = line;
529
358
  }
530
- function unlinkSingleRefedNode(delRoot) {
531
- let toUnlink;
532
- let node = delRoot,
533
- i = -1,
534
- parent;
535
- const stack = [];
536
- outer: do {
537
- let noGoDeep = false;
538
- doUnlink(toUnlink);
539
- toUnlink = null;
540
- noGoDeep = node.emitStart !== node.emitEnd;
541
- const recStart = node.recStart;
542
- if (recStart && !noGoDeep) {
543
- stack[++i] = recStart;
544
- parent = node;
545
- node = recStart.upstream;
546
- continue;
359
+ function outLink(up = null, down = null) {
360
+ const prevEmitLine = up.emitTail;
361
+ let recHead = down.recHead,
362
+ recTail = down.recTail,
363
+ scopeDown = down.scope;
364
+ const nextRec = recTail ? recTail.nextRecLine : recHead;
365
+ if (!nextRec) {
366
+ const line = {
367
+ execId: execId(),
368
+ up,
369
+ down,
370
+ prevEmitLine,
371
+ nextEmitLine: null,
372
+ prevRecLine: recTail,
373
+ nextRecLine: null,
374
+ nextOutLink: null,
375
+ prevOutLink: null
376
+ };
377
+ if (prevEmitLine) {
378
+ prevEmitLine.nextEmitLine = line;
379
+ } else {
380
+ up.emitHead = line;
547
381
  }
548
- while (true) {
549
- doUnlink(toUnlink);
550
- toUnlink = null;
551
- if (!noGoDeep) {
552
- toUnlink = node.emitStart;
553
- }
554
- noGoDeep = false;
555
- if (i === -1) {
556
- break outer;
557
- }
558
- const backLine = stack[i];
559
- const nextLine = backLine.nextRecLine;
560
- if (nextLine) {
561
- node = nextLine.upstream;
562
- stack[i] = nextLine;
563
- break;
564
- } else {
565
- node = parent;
566
- if (--i !== -1) {
567
- parent = stack[i].downstream;
568
- }
569
- }
382
+ up.emitTail = line;
383
+ if (recTail) {
384
+ recTail.nextRecLine = line;
385
+ } else {
386
+ down.recHead = line;
570
387
  }
571
- } while (true);
572
- doUnlink(toUnlink);
573
- }
574
- function doUnlink(line) {
575
- if (!line) {
388
+ down.recTail = line;
389
+ makeOutLink(scopeDown, line);
576
390
  return;
577
391
  }
578
- Line.unlink(line);
579
- }
580
- function dispose() {
581
- let toDel = this.recStart;
582
- while (toDel) {
583
- const memoNext = toDel.nextRecLine;
584
- const upstream = toDel.upstream;
585
- if (upstream.state & State.IsScope) {
586
- let node = upstream,
587
- i = -1,
588
- parent;
589
- const stack = [];
590
- outer: do {
591
- let noGoDeep = (node.state & State.IsScope) === 0 || node.state & ScopeAbort;
592
- const recStart = node.recStart;
593
- if (recStart && !noGoDeep) {
594
- stack[++i] = recStart;
595
- parent = node;
596
- node = recStart.upstream;
597
- continue;
598
- }
599
- while (true) {
600
- if (!noGoDeep) {
601
- releaseScope(node);
602
- }
603
- noGoDeep = false;
604
- if (i === -1) {
605
- break outer;
606
- }
607
- const backLine = stack[i];
608
- const nextLine = backLine.nextRecLine;
609
- if (nextLine) {
610
- node = nextLine.upstream;
611
- stack[i] = nextLine;
612
- break;
613
- } else {
614
- node = parent;
615
- if (--i !== -1) {
616
- parent = stack[i].downstream;
617
- }
618
- }
619
- }
620
- } while (true);
621
- } else {
622
- unlinkSingleLine(toDel);
623
- }
624
- toDel = memoNext;
392
+ if (nextRec.up === up) {
393
+ down.recTail = nextRec;
394
+ return;
625
395
  }
626
- releaseScope(this);
627
- doUnlink(this.emitStart);
628
- }
629
- function releaseScope(scope) {
630
- let outLink = scope.outLink;
631
- while (outLink) {
632
- const memoNext = outLink.nextOutLink;
633
- unlinkSingleLine(outLink);
634
- outLink = memoNext;
396
+ const line = {
397
+ execId: execId(),
398
+ up,
399
+ down,
400
+ prevEmitLine,
401
+ nextEmitLine: null,
402
+ prevRecLine: recTail,
403
+ nextRecLine: nextRec,
404
+ nextOutLink: null,
405
+ prevOutLink: null
406
+ };
407
+ if (prevEmitLine) {
408
+ prevEmitLine.nextEmitLine = line;
409
+ } else {
410
+ up.emitHead = line;
635
411
  }
636
- scope.state |= State.ScopeAbort;
637
- scope.clean?.();
638
- scope.clean = null;
639
- }
640
- function clean(cb) {
641
- G.PullingSignal.clean = () => runWithPulling(cb, null);
642
- }
643
- function runWithPulling(fn, signal) {
644
- const prevPulling = G.PullingSignal;
645
- G.PullingSignal = signal;
646
- const res = fn();
647
- G.PullingSignal = prevPulling;
648
- return res;
649
- }
650
- function getPulling() {
651
- return G.PullingSignal;
412
+ up.emitTail = line;
413
+ if (recHead) {
414
+ recTail.nextRecLine = line;
415
+ } else {
416
+ down.recHead = line;
417
+ }
418
+ down.recTail = line;
419
+ if (recTail) recTail.nextRecLine = line;
420
+ nextRec.prevRecLine = line;
421
+ makeOutLink(scopeDown, line);
652
422
  }
653
- function setPulling(pulling) {
654
- G.PullingSignal = pulling;
423
+ function makeOutLink(scopeDown, line) {
424
+ const first = scopeDown.outLink;
425
+ if (first) {
426
+ first.prevOutLink = line;
427
+ line.nextOutLink = first;
428
+ }
429
+ scopeDown.outLink = line;
655
430
  }
656
431
 
657
- const markDeep = root => {
658
- let node = root,
659
- i = -1,
660
- parent;
661
- const stack = [];
662
- outer: do {
663
- let noGoDeep = false;
664
- const state = node.state,
665
- emitStart = node.emitStart,
666
- scheduler = node.scheduler;
667
- if (node.scope && node.scope.state & State.ScopeAbort ||
668
- // scope 节点,且处于 ready 状态,不需要重复执行
669
- node.state & ScopeExecuted) {
670
- noGoDeep = true;
671
- } else {
672
- const inPullingArea = state & State.Pulling;
673
- const isEffect = parent !== void 0;
674
- const isLeaf = !emitStart || emitStart.downstream === node.scope;
675
- if (isEffect) {
676
- node.state |= inPullingArea ? State.PullingUnknown : State.Unknown;
677
- } else if (!isLeaf) {
678
- node.state |= State.Dirty;
432
+ class Computed {
433
+ emitHead = null;
434
+ emitTail = null;
435
+ recHead = null;
436
+ recTail = null;
437
+ state = 0;
438
+ scope = getPulling();
439
+ value = null;
440
+ constructor(callback) {
441
+ this.callback = callback;
442
+ }
443
+ get(shouldLink = true, notForceUpdate = true) {
444
+ const scope = this.scope;
445
+ if (scope && scope.state & 128) return this.value;
446
+ const down = getPulling();
447
+ if (this.recHead && notForceUpdate) {
448
+ if (this.state & 6) {
449
+ this.value = pullDeep(this);
679
450
  }
680
- if (isLeaf) {
681
- noGoDeep = true;
682
- if (isEffect && !inPullingArea) {
683
- const instance = _scheduler[scheduler];
684
- const item = instance.addEffect(node);
685
- instance.firstEffectItem ??= item;
686
- instance.lastEffectItem = item;
687
- }
451
+ } else {
452
+ this.state |= 1;
453
+ const nextId = execIdInc();
454
+ const prevId = execId();
455
+ setExecId(nextId);
456
+ setPulling(this);
457
+ this.recTail = null;
458
+ this.value = this.callback(this);
459
+ this.state &= -2;
460
+ setPulling(down);
461
+ setExecId(prevId);
462
+ transferDirtyState(this, this.state);
463
+ let line = this.recTail?.nextRecLine;
464
+ while (line) {
465
+ const nextLine = line.nextRecLine;
466
+ unlink(line, true);
467
+ line = nextLine;
688
468
  }
689
469
  }
690
- if (emitStart && !noGoDeep) {
691
- stack[++i] = emitStart;
692
- parent = node;
693
- node = emitStart.downstream;
694
- noGoDeep = false;
695
- continue;
470
+ if (shouldLink && down && (down.state & 256) === 0) {
471
+ link(this, down);
696
472
  }
697
- while (true) {
698
- if (i === -1) {
699
- break outer;
700
- }
701
- const backLine = stack[i];
702
- const nextLine = backLine.nextEmitLine;
703
- if (nextLine) {
704
- node = nextLine.downstream;
705
- stack[i] = nextLine;
706
- break;
707
- }
708
- node = parent;
709
- if (--i !== -1) {
710
- parent = stack[i].upstream;
711
- }
712
- }
713
- } while (true);
714
- };
715
- const pullingPostprocess = node => {
716
- let s = node.state;
717
- s &= ~State.Pulling;
718
- if (s & State.PullingUnknown) {
719
- s = s & ~State.PullingUnknown | State.Unknown;
473
+ return this.value;
720
474
  }
721
- node.state = s;
722
- };
475
+ }
476
+
723
477
  class Signal {
724
- constructor(nextValue, customPull) {
725
- this.nextValue = nextValue;
726
- this.customPull = customPull;
727
- this.version = -1;
728
- this.id = G.id++;
729
- this.state = State.Clean;
730
- /** 当前节点创建时处于的 effect 就是 scope */
731
- this.scope = G.PullingSignal;
732
- this.recEnd = null;
733
- this.recStart = null;
734
- this.emitStart = null;
735
- this.emitEnd = null;
736
- this.scheduler = null;
737
- this.value = null;
738
- this.outLink = null;
739
- this.pull = null;
740
- /** 记录当前 effect 中 clean */
741
- this.clean = null;
742
- }
743
- static {
744
- this.Pulling = null;
745
- }
746
- static create(nextValue, {
747
- customPull,
748
- isScope,
749
- scope,
750
- immediate,
751
- ...rest
752
- }) {
753
- const s = new Signal(nextValue, customPull);
754
- s.pull = s.customPull || s.DEFAULT_PULL;
755
- Object.assign(s, rest);
756
- if (isScope) {
757
- s.state |= State.IsScope;
758
- }
759
- if (scope !== void 0) {
760
- s.scope = scope;
761
- }
762
- return s;
763
- }
764
- DEFAULT_PULL() {
765
- return this.nextValue;
766
- }
767
- /**
768
- * 递归拉取负责建立以来链
769
- */
770
- pullRecurse(shouldLink = true) {
771
- G.PullingRecurseDeep++;
772
- const downstream = G.PullingSignal;
773
- this.linkWhenPull(downstream, shouldLink);
774
- try {
775
- if (this.version === G.version) {
776
- return this.value;
777
- }
778
- if (this.pull !== this.DEFAULT_PULL) this.recEnd = null;
779
- this.state |= State.Pulling;
780
- G.PullingSignal = this;
781
- this.clean?.();
782
- this.clean = null;
783
- let v = this.pull();
784
- if (this.state & State.IsScope && typeof v === "function") {
785
- const fn = v;
786
- this.clean = () => runWithPulling(fn, null);
787
- v = this.value;
478
+ scope = getPulling();
479
+ emitHead = null;
480
+ emitTail = null;
481
+ state = 0;
482
+ constructor(value) {
483
+ this.value = value;
484
+ }
485
+ get(shouldLink = true) {
486
+ if (shouldLink) {
487
+ const down = getPulling();
488
+ if (down && (down.state & 256) === 0) {
489
+ link(this, down);
788
490
  }
789
- this.value = v;
790
- this.version = G.version;
791
- return this.value;
792
- } catch (error) {
793
- console.error("\u8BA1\u7B97\u5C5E\u6027\u62A5\u9519\u8FD9\u6B21\u4E0D\u89E6\u53D1\uFF0C\u540E\u7EED\u72B6\u6001\u53EF\u80FD\u51FA\u9519", error);
794
- return this.value;
795
- } finally {
796
- this.pull = this.customPull || this.DEFAULT_PULL;
797
- pullingPostprocess(this);
798
- const toDel = this.recEnd?.nextRecLine;
799
- unlinkRecWithScope(toDel);
800
- G.PullingSignal = downstream;
801
- G.PullingRecurseDeep--;
802
- }
803
- }
804
- linkWhenPull(downstream, shouldLink) {
805
- const isScope = this.state & State.IsScope;
806
- if (
807
- // 2. 有下游
808
- downstream && shouldLink && (
809
- // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
810
- (downstream.state & State.LinkScopeOnly) === 0 || isScope) && (
811
- /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
812
- * 发生在 outEffect(() => scope(() => innerEffect(), null))
813
- * 虽然通过 scope 让 innerEffect 被管理,
814
- * 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
815
- * 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
816
- */
817
- !isScope || !this.emitStart)) {
818
- Line.link(this, downstream);
819
- }
820
- }
821
- pullDeep() {
822
- const signal = this;
823
- if (signal.state & DirtyState) {
824
- let node = signal,
825
- i = -1,
826
- parent;
827
- const stack = [];
828
- outer: do {
829
- let noGoDeep = false;
830
- if (node.state & (State.Pulling | State.Dirty) || (node.state & DirtyState) === 0 || node.isDisabled()) {
831
- noGoDeep = true;
832
- } else {
833
- node.state |= State.Pulling;
834
- }
835
- const recStart = node.recStart;
836
- if (recStart && !noGoDeep) {
837
- stack[++i] = recStart;
838
- parent = node;
839
- node = recStart.upstream;
840
- continue;
841
- }
842
- while (true) {
843
- const isDirty = node.state & State.Dirty;
844
- let currentClean = noGoDeep && !isDirty;
845
- if (noGoDeep && node.state & State.Pulling) {
846
- currentClean = true;
847
- }
848
- let noGoSibling = false;
849
- const downstream2 = parent;
850
- const isEmitter = node.pull === node.DEFAULT_PULL;
851
- if (currentClean) ; else if (isDirty) {
852
- if (isEmitter && node.value !== node.nextValue) {
853
- node.markDownStreamsDirty();
854
- node.state &= ~State.Dirty;
855
- } else {
856
- const prevPulling = G.PullingSignal;
857
- G.PullingSignal = downstream2;
858
- const prevValue = node.value;
859
- node.pullRecurse(false);
860
- if (prevValue !== node.value) {
861
- node.markDownStreamsDirty();
862
- }
863
- node.state &= ~State.Dirty;
864
- G.PullingSignal = prevPulling;
865
- noGoSibling = true;
866
- }
867
- } else if (node.state & State.Unknown) {
868
- node.state &= ~State.Unknown;
869
- }
870
- if (!isEmitter) {
871
- node.version = G.version;
872
- }
873
- pullingPostprocess(node);
874
- noGoDeep = false;
875
- if (i === -1) {
876
- break outer;
877
- }
878
- const backLine = stack[i];
879
- const nextLine = backLine.nextRecLine;
880
- if (!noGoSibling && nextLine) {
881
- node = nextLine.upstream;
882
- stack[i] = nextLine;
883
- break;
884
- } else {
885
- node = parent;
886
- if (--i !== -1) {
887
- parent = stack[i].downstream;
888
- }
889
- }
890
- }
891
- } while (true);
892
491
  }
893
- const downstream = G.PullingSignal;
894
- this.linkWhenPull(downstream, true);
895
492
  return this.value;
896
493
  }
897
- get v() {
898
- if (this.isDisabled()) {
899
- return this.value;
900
- }
901
- if (!this.recStart || this.pull === this.DEFAULT_PULL) {
902
- return this.pullRecurse(true);
903
- }
904
- return this.pullDeep();
905
- }
906
- // pause() {
907
- // this.state |= State.SelfPaused;
908
- // }
909
- // resume() {
910
- // this.state &= ~State.SelfPaused;
911
- // }
912
- markDownStreamsDirty() {
913
- let point = this.emitStart;
914
- while (point != null) {
915
- const downstream = point.downstream;
916
- downstream.state |= State.Dirty;
917
- downstream.state &= ~State.Unknown;
918
- point = point.nextEmitLine;
494
+ set(v) {
495
+ if (this.value === v) return;
496
+ this.value = v;
497
+ if (this.emitHead) {
498
+ mark(this);
499
+ if (batchDeep() === 0) {
500
+ flushEffect();
501
+ }
919
502
  }
920
503
  }
921
- set v(v) {
922
- if (this.isDisabled() || this.nextValue === v) {
923
- return;
924
- }
925
- this.nextValue = v;
926
- this.pull = this.DEFAULT_PULL;
927
- G.version++;
928
- if (this.emitStart) {
929
- markDeep(this);
930
- if (batchDeep === 0) {
931
- this.scheduleEffect();
504
+ }
505
+
506
+ const EffectState = 512 | 32;
507
+ class Effect {
508
+ emitHead = null;
509
+ emitTail = null;
510
+ recHead = null;
511
+ recTail = null;
512
+ state = EffectState;
513
+ scope = getPulling();
514
+ outLink = null;
515
+ clean = null;
516
+ constructor(callback) {
517
+ this.callback = callback;
518
+ this.get();
519
+ }
520
+ get(shouldLink = true, notForceUpdate = true) {
521
+ if (this.state & 128) return;
522
+ const down = getPulling();
523
+ if (this.recHead && notForceUpdate) {
524
+ pullDeep(this);
525
+ } else {
526
+ this.state |= 1;
527
+ setPulling(null);
528
+ this.clean?.();
529
+ this.clean = null;
530
+ const nextId = execIdInc();
531
+ const prevId = execId();
532
+ setExecId(nextId);
533
+ setPulling(this);
534
+ this.recTail = null;
535
+ const res = this.callback(this);
536
+ typeof res === 'function' && (this.clean = res);
537
+ this.state &= -2;
538
+ setPulling(down);
539
+ setExecId(prevId);
540
+ transferDirtyState(this, this.state);
541
+ let line = this.recTail?.nextRecLine;
542
+ while (line) {
543
+ const nextLine = line.nextRecLine;
544
+ unlink(line, true);
545
+ line = nextLine;
932
546
  }
933
547
  }
934
- }
935
- scheduleEffect() {
936
- for (const key in _scheduler) {
937
- const instance = _scheduler[key];
938
- instance.endSet();
548
+ if (!this.emitHead && shouldLink && down) {
549
+ link(this, down);
939
550
  }
940
551
  }
941
- /** 返回值为 true 表示已处理 */
942
- runIfDirty() {
943
- this.state & (State.Unknown | State.Dirty) && this.v;
944
- }
945
- isDisabled() {
946
- return (
947
- // scope 被取消
948
- this.scope && this.scope.state & State.ScopeAbort ||
949
- // scope 节点,且处于 ready 状态,不需要重复执行
950
- this.state & ScopeExecuted
951
- );
552
+ }
553
+ Effect.prototype.dispose = dispose;
554
+
555
+ const ScopeAndLinkScopeOnly = 32 | 256;
556
+ class Scope {
557
+ emitHead = null;
558
+ emitTail = null;
559
+ recHead = null;
560
+ recTail = null;
561
+ state = ScopeAndLinkScopeOnly;
562
+ scope = getPulling();
563
+ outLink = null;
564
+ constructor(callback) {
565
+ this.callback = callback;
566
+ }
567
+ get(shouldLink = true) {
568
+ const scope = this.scope;
569
+ this.state |= 1;
570
+ setPulling(this);
571
+ this.recTail = null;
572
+ const res = this.callback();
573
+ typeof res === 'function' && (this.clean = res);
574
+ this.state &= -2;
575
+ setPulling(scope);
576
+ if (!this.emitHead && shouldLink && scope) {
577
+ link(this, scope);
578
+ }
952
579
  }
953
580
  }
954
- let batchDeep = 0;
955
- function batchStart() {
956
- batchDeep++;
581
+ Scope.prototype.dispose = dispose;
582
+
583
+ let Keys = function (Keys) {
584
+ Keys["Iterator"] = "__AOYE_ITERATOR";
585
+ Keys["Raw"] = "__AOYE_RAW";
586
+ Keys["Meta"] = "__AOYE_META";
587
+ return Keys;
588
+ }({});
589
+ const IsStore = Symbol('__AOYE_IS_STORE'),
590
+ StoreIgnoreKeys = Symbol('__AOYE_IGNORE_KEYS');
591
+
592
+ const rawToProxy = new WeakMap();
593
+ let State = function (State) {
594
+ State[State["Clean"] = 0] = "Clean";
595
+ State[State["LinkScopeOnly"] = 256] = "LinkScopeOnly";
596
+ State[State["ScopeAbort"] = 128] = "ScopeAbort";
597
+ State[State["ScopeReady"] = 64] = "ScopeReady";
598
+ State[State["IsScope"] = 32] = "IsScope";
599
+ State[State["PullingDirty"] = 16] = "PullingDirty";
600
+ State[State["PullingUnknown"] = 8] = "PullingUnknown";
601
+ State[State["Unknown"] = 4] = "Unknown";
602
+ State[State["Dirty"] = 2] = "Dirty";
603
+ State[State["Pulling"] = 1] = "Pulling";
604
+ return State;
605
+ }({});
606
+ State.Unknown | State.Dirty;
607
+ State.ScopeReady | State.ScopeAbort;
608
+ State.ScopeAbort;
609
+
610
+ const ide = globalThis.requestIdleCallback || (globalThis.requestAnimationFrame ? fn => globalThis.requestAnimationFrame(() => {
611
+ setTimeout(() => {
612
+ fn();
613
+ });
614
+ }) : globalThis.setTimeout);
615
+ const now = () => {
616
+ const timer = globalThis.performance || globalThis.Date;
617
+ return timer.now();
618
+ };
619
+ let channel = globalThis.MessageChannel ? new MessageChannel() : null;
620
+ if (globalThis.MessageChannel) {
621
+ channel = new MessageChannel();
957
622
  }
958
- function batchEnd() {
959
- if (--batchDeep) return;
960
- for (const key in _scheduler) {
961
- const instance = _scheduler[key];
962
- instance.endSet();
623
+ let msgId = 0;
624
+ const macro = fn => {
625
+ if (!channel) {
626
+ setTimeout(fn);
963
627
  }
964
- }
628
+ const memoId = msgId;
629
+ function onMessage(e) {
630
+ if (memoId === e.data) {
631
+ fn();
632
+ channel.port2.removeEventListener('message', onMessage);
633
+ }
634
+ }
635
+ channel.port2.addEventListener('message', onMessage);
636
+ channel.port1.postMessage(msgId++);
637
+ };
638
+ const p = Promise.resolve();
639
+ const micro = cb => {
640
+ p.then(cb);
641
+ };
642
+ const toRaw = a => {
643
+ if (typeof a === 'object' && a !== null && a[Keys.Raw]) {
644
+ return toRaw(a[Keys.Raw]);
645
+ }
646
+ return a;
647
+ };
965
648
 
966
649
  const deepSignal = (target, scope, deep = true) => {
967
- const isObj = typeof target === "object" && target !== null;
650
+ const isObj = typeof target === 'object' && target !== null;
968
651
  if (!isObj || target[Keys.Raw]) return target;
969
652
  const p = rawToProxy.get(target);
970
653
  if (p) return p;
971
- const cells = /* @__PURE__ */new Map();
654
+ const cells = new Map();
972
655
  const targetIsArray = Array.isArray(target);
973
656
  const targetIsStore = Boolean(target.constructor?.[IsStore]);
974
657
  const meta = {
@@ -989,12 +672,12 @@
989
672
  return Reflect.get(obj, prop, receiver);
990
673
  }
991
674
  const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
992
- const isGetter = desc && typeof desc.get === "function";
675
+ const isGetter = desc && typeof desc.get === 'function';
993
676
  if (isGetter) {
994
677
  return handleGetterAsComputed(obj, prop, receiver, cells, scope);
995
678
  }
996
679
  const value = Reflect.get(obj, prop, receiver);
997
- const valueIsFn = typeof value === "function";
680
+ const valueIsFn = typeof value === 'function';
998
681
  if (valueIsFn) {
999
682
  if (targetIsArray) {
1000
683
  return arrayMethodReWrites[prop] || value;
@@ -1004,26 +687,22 @@
1004
687
  }
1005
688
  let s = cells.get(prop);
1006
689
  if (s) {
1007
- return s.v;
690
+ return s.get();
1008
691
  }
1009
692
  const wrappedValue = deep ? deepSignal(value, scope) : value;
1010
- s = Signal.create(wrappedValue, {
1011
- scheduler: Scheduler.Sync,
1012
- isScope: false,
1013
- scope
1014
- });
693
+ s = new Signal(wrappedValue);
1015
694
  cells.set(prop, s);
1016
- return s.v;
695
+ return s.get();
1017
696
  },
1018
697
  set(obj, prop, value, receiver) {
1019
- if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === "function") {
698
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === 'function') {
1020
699
  return Reflect.set(obj, prop, value, receiver);
1021
700
  }
1022
701
  batchStart();
1023
702
  const success = Reflect.set(obj, prop, value, receiver);
1024
703
  const cell = cells.get(prop);
1025
704
  if (cell) {
1026
- cell.v = deep ? deepSignal(value, scope) : value;
705
+ cell.set(deep ? deepSignal(value, scope) : value);
1027
706
  }
1028
707
  if (targetIsArray) {
1029
708
  handleArraySet(obj, prop, value, receiver);
@@ -1033,13 +712,12 @@
1033
712
  batchEnd();
1034
713
  return success;
1035
714
  },
1036
- // 【核心修改】拦截 delete 操作
1037
715
  deleteProperty(obj, prop) {
1038
- if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof obj[prop] === "function") {
716
+ if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof obj[prop] === 'function') {
1039
717
  return Reflect.deleteProperty(obj, prop);
1040
718
  }
1041
719
  cells.delete(prop);
1042
- triggerIter(obj, prop, void 0, proxy);
720
+ triggerIter(obj, prop, undefined, proxy);
1043
721
  return Reflect.deleteProperty(obj, prop);
1044
722
  },
1045
723
  ownKeys(obj) {
@@ -1056,8 +734,8 @@
1056
734
  };
1057
735
  const shareSignal = (from, fromPath, to, toPath) => {
1058
736
  try {
1059
- const toPaths = toPath.split(".");
1060
- const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
737
+ const toPaths = toPath.split('.');
738
+ const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split('.');
1061
739
  runWithPulling(() => {
1062
740
  const _getTargetAndKey = getTargetAndKey(from, formPaths),
1063
741
  fromTarget = _getTargetAndKey.target,
@@ -1071,13 +749,13 @@
1071
749
  toTarget[Keys.Raw][toKey] = val;
1072
750
  }, null);
1073
751
  } catch (error) {
1074
- console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
752
+ console.error('映射了不存在的Key!');
1075
753
  throw error;
1076
754
  }
1077
755
  };
1078
756
  function getTargetAndKey(obj, paths) {
1079
757
  let target = obj;
1080
- let key = "";
758
+ let key = '';
1081
759
  const len = paths.length;
1082
760
  for (let i = 0; i < len; i++) {
1083
761
  key = paths[i];
@@ -1091,27 +769,23 @@
1091
769
  };
1092
770
  }
1093
771
  function isIgnoreKey(ignores, key) {
1094
- if (typeof key !== "string") {
772
+ if (typeof key !== 'string') {
1095
773
  return ignores.includes(key);
1096
774
  }
1097
- return ignores.some(it => typeof it === "string" && key.startsWith(it));
775
+ return ignores.some(it => typeof it === 'string' && key.startsWith(it));
1098
776
  }
1099
777
  function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1100
778
  let s = cells.get(prop);
1101
779
  if (s) {
1102
- return s.v;
780
+ return s.get();
1103
781
  }
1104
- s = Signal.create(null, {
1105
- customPull: () => Reflect.get(obj, prop, receiver),
1106
- scheduler: Scheduler.Sync,
1107
- isScope: false,
1108
- scope
1109
- });
782
+ s = new Computed(() => Reflect.get(obj, prop, receiver));
783
+ s.scope = scope;
1110
784
  cells.set(prop, s);
1111
- return s.v;
785
+ return s.get();
1112
786
  }
1113
787
  function handleArraySet(arr, prop, value, receiver) {
1114
- if (prop === "length") ; else if (bobeShared.isNatureNumStr(prop)) {
788
+ if (prop === 'length') ; else if (bobeShared.isNatureNumStr(prop)) {
1115
789
  receiver[Keys.Iterator] = (arr[Keys.Iterator] || 0) + 1;
1116
790
  } else {
1117
791
  triggerIter(arr, prop, value, receiver);
@@ -1119,11 +793,11 @@
1119
793
  }
1120
794
  function triggerIter(obj, prop, value, receiver) {
1121
795
  if (!Reflect.has(obj, prop)) {
1122
- receiver[Keys.Iterator] = receiver[Keys.Raw][Keys.Iterator] + 1;
796
+ receiver[Keys.Iterator] = (receiver[Keys.Raw][Keys.Iterator] || 0) + 1;
1123
797
  }
1124
798
  }
1125
799
  const arrayMethodReWrites = {};
1126
- ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(key => {
800
+ ['pop', 'push', 'shift', 'splice', 'unshift', 'copyWithin', 'reverse', 'fill'].forEach(key => {
1127
801
  arrayMethodReWrites[key] = function (...args) {
1128
802
  batchStart();
1129
803
  const fn = Array.prototype[key];
@@ -1133,13 +807,13 @@
1133
807
  return res;
1134
808
  };
1135
809
  });
1136
- ["includes", "indexOf", "lastIndexOf"].forEach(key => {
810
+ ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
1137
811
  arrayMethodReWrites[key] = function (...args) {
1138
812
  const fn = Array.prototype[key];
1139
813
  const that = toRaw(this);
1140
814
  let result = fn.call(that, ...args);
1141
815
  const value = args[0];
1142
- if ((result === false || result === -1) && typeof value === "object" && value !== null) {
816
+ if ((result === false || result === -1) && typeof value === 'object' && value !== null) {
1143
817
  if (value[Keys.Raw]) {
1144
818
  args[0] = value[Keys.Raw];
1145
819
  result = fn.call(that, ...args);
@@ -1154,8 +828,8 @@
1154
828
  return result;
1155
829
  };
1156
830
  });
1157
- [Symbol.iterator, "values", "entries"].forEach(key => {
1158
- const isEntries = key === "entries";
831
+ [Symbol.iterator, 'values', 'entries'].forEach(key => {
832
+ const isEntries = key === 'entries';
1159
833
  arrayMethodReWrites[key] = function (...args) {
1160
834
  const fn = Array.prototype[key];
1161
835
  const rawArray = toRaw(this);
@@ -1213,7 +887,7 @@
1213
887
  } else {
1214
888
  k = Math.min(k, len);
1215
889
  }
1216
- let final = end === void 0 ? len : end;
890
+ let final = end === undefined ? len : end;
1217
891
  if (final < 0) {
1218
892
  final = Math.max(len + final, 0);
1219
893
  } else {
@@ -1341,42 +1015,42 @@
1341
1015
  };
1342
1016
  const GetMethodConf = {
1343
1017
  wrapReturn: false,
1344
- wrapArgs: 1
1018
+ wrapArgs: 0b01
1345
1019
  };
1346
1020
  [{
1347
- key: "every",
1021
+ key: 'every',
1348
1022
  ...GetMethodConf
1349
1023
  }, {
1350
- key: "find",
1024
+ key: 'find',
1351
1025
  wrapReturn: true,
1352
1026
  ...GetMethodConf
1353
1027
  }, {
1354
- key: "findLast",
1028
+ key: 'findLast',
1355
1029
  ...GetMethodConf,
1356
1030
  wrapReturn: true
1357
1031
  }, {
1358
- key: "findIndex",
1032
+ key: 'findIndex',
1359
1033
  ...GetMethodConf
1360
1034
  }, {
1361
- key: "findLastIndex",
1035
+ key: 'findLastIndex',
1362
1036
  ...GetMethodConf
1363
1037
  }, {
1364
- key: "forEach",
1038
+ key: 'forEach',
1365
1039
  ...GetMethodConf
1366
1040
  }, {
1367
- key: "map",
1041
+ key: 'map',
1368
1042
  ...GetMethodConf
1369
1043
  }, {
1370
- key: "some",
1044
+ key: 'some',
1371
1045
  ...GetMethodConf
1372
1046
  }, {
1373
- key: "reduce",
1047
+ key: 'reduce',
1374
1048
  ...GetMethodConf,
1375
- wrapArgs: 2
1049
+ wrapArgs: 0b10
1376
1050
  }, {
1377
- key: "reduceRight",
1051
+ key: 'reduceRight',
1378
1052
  ...GetMethodConf,
1379
- wrapArgs: 2
1053
+ wrapArgs: 0b10
1380
1054
  }].forEach(({
1381
1055
  key,
1382
1056
  wrapReturn,
@@ -1398,17 +1072,17 @@
1398
1072
  };
1399
1073
  });
1400
1074
  arrayMethodReWrites.toSorted = function (...args) {
1401
- const fn = Array.prototype["toSorted"];
1075
+ const fn = Array.prototype['toSorted'];
1402
1076
  const meta = this[Keys.Meta];
1403
1077
  const isDeep = meta.deep,
1404
1078
  scope = meta.scope;
1405
1079
  const that = toRaw(this);
1406
- warpCallbackArgs(isDeep, args, scope, 3);
1080
+ warpCallbackArgs(isDeep, args, scope, 0b11);
1407
1081
  let result = fn.call(that, ...args);
1408
1082
  this[Keys.Iterator];
1409
1083
  return isDeep ? result.map(it => deepSignal(it, scope)) : result;
1410
1084
  };
1411
- ["join", "toString", "toLocaleString"].forEach(key => {
1085
+ ['join', 'toString', 'toLocaleString'].forEach(key => {
1412
1086
  arrayMethodReWrites[key] = function (...args) {
1413
1087
  const fn = Array.prototype[key];
1414
1088
  const that = toRaw(this);
@@ -1417,38 +1091,30 @@
1417
1091
  return result;
1418
1092
  };
1419
1093
  });
1420
- function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
1094
+ function warpCallbackArgs(isDeep, args, scope, wrapArgs = 0b01) {
1421
1095
  const callback = args[0];
1422
1096
  const wrapCb = function (...cbArgs) {
1423
1097
  if (isDeep) {
1424
- if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
1425
- if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
1098
+ if (wrapArgs & 0b01) cbArgs[0] = deepSignal(cbArgs[0], scope);
1099
+ if (wrapArgs & 0b10) cbArgs[1] = deepSignal(cbArgs[1], scope);
1426
1100
  }
1427
1101
  return callback.call(this, ...cbArgs);
1428
1102
  };
1429
1103
  args[0] = wrapCb;
1430
1104
  }
1431
1105
 
1432
- var _a, _b;
1433
- _b = IsStore, _a = StoreIgnoreKeys;
1434
- const _Store = class _Store {
1106
+ class Store {
1107
+ static [IsStore] = true;
1108
+ static [StoreIgnoreKeys] = ['ui', 'raw'];
1109
+ static Current = null;
1435
1110
  constructor() {
1436
- this.parent = () => null;
1437
- const proxy = deepSignal(this, G.PullingSignal, true);
1438
- _Store.Current = proxy;
1111
+ const proxy = deepSignal(this, getPulling(), true);
1112
+ Store.Current = proxy;
1439
1113
  return proxy;
1440
1114
  }
1441
- static {
1442
- this[_b] = true;
1443
- }
1444
- static {
1445
- this[_a] = ["ui", "raw"];
1446
- }
1447
- static {
1448
- this.Current = null;
1449
- }
1115
+ parent = () => null;
1450
1116
  static new(keyMap = {}, staticMap = {}) {
1451
- const parentStore = _Store.Current;
1117
+ const parentStore = Store.Current;
1452
1118
  const child = new this();
1453
1119
  if (parentStore) {
1454
1120
  for (const childKey in keyMap) {
@@ -1461,7 +1127,7 @@
1461
1127
  child[key] = value;
1462
1128
  }
1463
1129
  child.parent = () => parentStore;
1464
- _Store.Current = parentStore;
1130
+ Store.Current = parentStore;
1465
1131
  return child;
1466
1132
  }
1467
1133
  map(keyMap = {}) {
@@ -1474,56 +1140,44 @@
1474
1140
  }
1475
1141
  this.parent = null;
1476
1142
  }
1477
- };
1478
- let Store = _Store;
1143
+ }
1479
1144
 
1480
- const DefaultCustomSignalOpt = {
1481
- /** 三种模式
1482
- * 1. auto: 根据值类型自动判断 默认
1483
- * 2. ref: 对任何值使用 {v: xxx} 进行包装
1484
- * 3. proxy: 使用 proxy 进行包装
1485
- */
1486
- mode: "auto",
1487
- /** 是否深度响应式 */
1488
- deep: true
1489
- };
1490
- ({
1491
- scheduler: Scheduler.Sync});
1492
- const $ = (init, opt = {}) => {
1493
- opt = {
1494
- ...DefaultCustomSignalOpt,
1495
- ...opt
1496
- };
1497
- let intiValue, customPull;
1498
- if (typeof init === "function") {
1499
- intiValue = null;
1500
- customPull = init;
1501
- } else if (opt.mode !== "ref" && typeof init === "object" && init !== null) {
1502
- return deepSignal(init, G.PullingSignal, opt.deep);
1145
+ function $(data) {
1146
+ if (typeof data === 'object' && data !== null) {
1147
+ return deepSignal(data, getPulling());
1148
+ }
1149
+ if (typeof data === 'function') {
1150
+ const s = new Computed(data),
1151
+ get = s.get.bind(s);
1152
+ return {
1153
+ ins: s,
1154
+ get v() {
1155
+ return get();
1156
+ }
1157
+ };
1503
1158
  } else {
1504
- intiValue = init;
1159
+ const s = new Signal(data),
1160
+ set = s.set.bind(s),
1161
+ get = s.get.bind(s);
1162
+ return {
1163
+ ins: s,
1164
+ get v() {
1165
+ return get();
1166
+ },
1167
+ set v(v) {
1168
+ set(v);
1169
+ }
1170
+ };
1505
1171
  }
1506
- const s = Signal.create(intiValue, {
1507
- scheduler: Scheduler.Sync,
1508
- isScope: false,
1509
- customPull
1510
- });
1511
- return s;
1512
- };
1513
- const effect = (customPull, depOrOpt, opt) => {
1172
+ }
1173
+ function effectUt(callback, depOrOpt, opt) {
1514
1174
  const hasDep = Array.isArray(depOrOpt);
1515
1175
  opt = hasDep ? opt || {} : depOrOpt || {};
1516
1176
  if (!hasDep) {
1517
- const s2 = Signal.create(null, {
1518
- customPull,
1519
- scheduler: Scheduler.Sync,
1520
- isScope: true,
1521
- ...opt
1522
- });
1523
- s2.v;
1524
- const bound2 = dispose.bind(s2);
1525
- bound2.ins = s2;
1526
- return bound2;
1177
+ const ef = new Effect(callback);
1178
+ const run = ef.dispose.bind(ef);
1179
+ run.ins = ef;
1180
+ return run;
1527
1181
  }
1528
1182
  let mounted = false;
1529
1183
  const deps = depOrOpt;
@@ -1534,84 +1188,94 @@
1534
1188
  old: null,
1535
1189
  val: null
1536
1190
  }));
1537
- const s = Signal.create(null, {
1538
- customPull() {
1539
- for (let i = 0; i < deps.length; i++) {
1540
- const value = deps[i].v;
1541
- vs[i].old = vs[i].val;
1542
- vs[i].val = value;
1543
- }
1544
- if (mounted || immediate) {
1545
- s.state |= State.LinkScopeOnly;
1546
- customPull(...vs);
1547
- s.state &= ~State.LinkScopeOnly;
1548
- }
1549
- mounted = true;
1550
- },
1551
- scheduler: Scheduler.Sync,
1552
- isScope: true,
1553
- ...opt
1554
- });
1555
- s.v;
1556
- const bound = dispose.bind(s);
1557
- bound.ins = s;
1558
- return bound;
1559
- };
1560
- const scope = (...args) => {
1561
- const hasScope = args.length > 1;
1562
- const s = Signal.create(null, {
1563
- customPull: args[0],
1564
- scheduler: Scheduler.Sync,
1565
- isScope: true,
1566
- scope: hasScope ? args[1] : G.PullingSignal
1191
+ const ef = new Effect(() => {
1192
+ for (let i = 0; i < deps.length; i++) {
1193
+ const value = deps[i].v;
1194
+ vs[i].old = vs[i].val;
1195
+ vs[i].val = value;
1196
+ }
1197
+ if (mounted || immediate) {
1198
+ ef.state |= 256;
1199
+ callback(...vs);
1200
+ ef.state &= -257;
1201
+ }
1202
+ mounted = true;
1567
1203
  });
1568
- if (hasScope) {
1569
- runWithPulling(() => {
1570
- s.v;
1571
- }, args[1]);
1572
- } else {
1573
- s.v;
1204
+ const run = ef.dispose.bind(ef);
1205
+ run.ins = ef;
1206
+ return run;
1207
+ }
1208
+ function effect(callback, depOrOpt, opt) {
1209
+ const hasDep = Array.isArray(depOrOpt);
1210
+ opt = hasDep ? opt || {} : depOrOpt || {};
1211
+ if (!hasDep) {
1212
+ const ef = new Effect(callback);
1213
+ const run = ef.dispose.bind(ef);
1214
+ run.ins = ef;
1215
+ return run;
1574
1216
  }
1575
- s.state |= State.ScopeReady;
1576
- const bound = dispose.bind(s);
1577
- bound.ins = s;
1578
- return bound;
1579
- };
1580
- const customEffect = opt => {
1581
- return (init, innerOpt = {}) => {
1582
- return effect(init, {
1583
- ...opt,
1584
- ...innerOpt
1585
- });
1586
- };
1587
- };
1588
- const isSignal = value => {
1589
- return value instanceof Signal;
1590
- };
1591
- const isScope = value => {
1592
- return value instanceof Signal;
1593
- };
1217
+ let mounted = false;
1218
+ const deps = depOrOpt;
1219
+ const immediate = deps.length === 0 ? true : opt.immediate ?? true;
1220
+ const vs = Array.from({
1221
+ length: deps.length
1222
+ }, () => ({
1223
+ old: null,
1224
+ val: null
1225
+ }));
1226
+ const ef = new Effect(eff => {
1227
+ for (let i = 0; i < deps.length; i++) {
1228
+ const value = deps[i].get();
1229
+ vs[i].old = vs[i].val;
1230
+ vs[i].val = value;
1231
+ }
1232
+ if (mounted || immediate) {
1233
+ eff.state |= 256;
1234
+ callback(...vs);
1235
+ eff.state &= -257;
1236
+ }
1237
+ mounted = true;
1238
+ });
1239
+ const run = ef.dispose.bind(ef);
1240
+ run.ins = ef;
1241
+ return run;
1242
+ }
1243
+ function scope(...args) {
1244
+ const ins = new Scope(args[0]);
1245
+ if (args.length === 2) {
1246
+ ins.scope = args[1];
1247
+ }
1248
+ ins.get();
1249
+ const run = ins.dispose.bind(ins);
1250
+ run.ins = ins;
1251
+ return run;
1252
+ }
1594
1253
 
1595
1254
  exports.$ = $;
1255
+ exports.Computed = Computed;
1256
+ exports.Effect = Effect;
1596
1257
  exports.IsStore = IsStore;
1597
1258
  exports.Keys = Keys;
1598
- exports.Scheduler = Scheduler;
1259
+ exports.Scope = Scope;
1599
1260
  exports.Signal = Signal;
1600
1261
  exports.Store = Store;
1601
1262
  exports.StoreIgnoreKeys = StoreIgnoreKeys;
1602
- exports.TaskQueue = TaskQueue;
1603
1263
  exports.batchEnd = batchEnd;
1604
1264
  exports.batchStart = batchStart;
1605
1265
  exports.clean = clean;
1606
- exports.customEffect = customEffect;
1607
1266
  exports.deepSignal = deepSignal;
1608
1267
  exports.effect = effect;
1268
+ exports.effectUt = effectUt;
1269
+ exports.execId = execId;
1270
+ exports.execIdInc = execIdInc;
1609
1271
  exports.getPulling = getPulling;
1610
- exports.isScope = isScope;
1611
- exports.isSignal = isSignal;
1612
- exports.registerScheduler = registerScheduler;
1272
+ exports.ide = ide;
1273
+ exports.macro = macro;
1274
+ exports.micro = micro;
1275
+ exports.now = now;
1613
1276
  exports.runWithPulling = runWithPulling;
1614
1277
  exports.scope = scope;
1278
+ exports.setExecId = setExecId;
1615
1279
  exports.setPulling = setPulling;
1616
1280
  exports.shareSignal = shareSignal;
1617
1281
  exports.toRaw = toRaw;