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