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