aoye 0.0.21 → 0.0.23
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 +422 -381
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +421 -381
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +38 -43
- package/dist/index.umd.js +422 -381
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/aoye.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseEvent, Queue, isNatureNumStr } from 'bobe-shared';
|
|
2
2
|
|
|
3
|
-
const rawToProxy = /* @__PURE__ */
|
|
3
|
+
const rawToProxy = /* @__PURE__ */new WeakMap();
|
|
4
4
|
new BaseEvent();
|
|
5
5
|
const G = {
|
|
6
6
|
/** 原子 signal 更新次数 */
|
|
@@ -12,7 +12,7 @@ const G = {
|
|
|
12
12
|
/** 表示当前处于 pull 递归中 */
|
|
13
13
|
PullingRecurseDeep: 0
|
|
14
14
|
};
|
|
15
|
-
var State = /* @__PURE__ */
|
|
15
|
+
var State = /* @__PURE__ */(State2 => {
|
|
16
16
|
State2[State2["Clean"] = 0] = "Clean";
|
|
17
17
|
State2[State2["LinkScopeOnly"] = 256] = "LinkScopeOnly";
|
|
18
18
|
State2[State2["ScopeAbort"] = 128] = "ScopeAbort";
|
|
@@ -33,7 +33,12 @@ const leakI = (y, max) => y < 0 || y >= max ? null : y;
|
|
|
33
33
|
const getLeft = (x, max) => leakI(x * 2 + 1, max);
|
|
34
34
|
const getRight = (x, max) => leakI(x * 2 + 2, max);
|
|
35
35
|
const getParent = (x, max) => leakI(x - 1 >>> 1, max);
|
|
36
|
-
const exchange = (arr, i, j) =>
|
|
36
|
+
const exchange = (arr, i, j) => {
|
|
37
|
+
var _ref = [arr[j], arr[i]];
|
|
38
|
+
arr[i] = _ref[0];
|
|
39
|
+
arr[j] = _ref[1];
|
|
40
|
+
return _ref;
|
|
41
|
+
};
|
|
37
42
|
class PriorityQueue {
|
|
38
43
|
// 构造函数接受一个compare函数
|
|
39
44
|
// compare返回的-1, 0, 1决定元素是否优先被去除
|
|
@@ -85,11 +90,11 @@ class PriorityQueue {
|
|
|
85
90
|
this.goUp(this.arr, current, len);
|
|
86
91
|
}
|
|
87
92
|
add(...items) {
|
|
88
|
-
items.forEach(
|
|
93
|
+
items.forEach(it => this._add(it));
|
|
89
94
|
}
|
|
90
95
|
// 去除头元素并返回
|
|
91
96
|
poll() {
|
|
92
|
-
const
|
|
97
|
+
const arr = this.arr;
|
|
93
98
|
const len = this.size();
|
|
94
99
|
if (len <= 2) {
|
|
95
100
|
return arr.shift();
|
|
@@ -109,7 +114,7 @@ class PriorityQueue {
|
|
|
109
114
|
return this.arr.length;
|
|
110
115
|
}
|
|
111
116
|
logTree() {
|
|
112
|
-
const
|
|
117
|
+
const arr = this.arr;
|
|
113
118
|
let i = 0;
|
|
114
119
|
let j = 1;
|
|
115
120
|
let level = 0;
|
|
@@ -123,7 +128,7 @@ class PriorityQueue {
|
|
|
123
128
|
const last = Math.pow(2, matrix.length - 1);
|
|
124
129
|
const arrStr = JSON.stringify(last);
|
|
125
130
|
const halfLen = arrStr.length >>> 1;
|
|
126
|
-
matrix.forEach(
|
|
131
|
+
matrix.forEach(it => {
|
|
127
132
|
const str = JSON.stringify(it);
|
|
128
133
|
const halfIt = str.length >>> 1;
|
|
129
134
|
console.log(str.padStart(halfLen + halfIt, " "));
|
|
@@ -132,22 +137,6 @@ class PriorityQueue {
|
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
|
|
135
|
-
var __defProp$3 = Object.defineProperty;
|
|
136
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
137
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
138
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
139
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
140
|
-
var __spreadValues$3 = (a, b) => {
|
|
141
|
-
for (var prop in b || (b = {}))
|
|
142
|
-
if (__hasOwnProp$4.call(b, prop))
|
|
143
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
144
|
-
if (__getOwnPropSymbols$4)
|
|
145
|
-
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
146
|
-
if (__propIsEnum$4.call(b, prop))
|
|
147
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
148
|
-
}
|
|
149
|
-
return a;
|
|
150
|
-
};
|
|
151
140
|
const DefaultTaskControlReturn = {
|
|
152
141
|
finished: true,
|
|
153
142
|
startNewCallbackAble: true
|
|
@@ -158,13 +147,17 @@ class TaskQueue {
|
|
|
158
147
|
this.aIsUrgent = aIsUrgent;
|
|
159
148
|
this.isScheduling = false;
|
|
160
149
|
}
|
|
161
|
-
static create({
|
|
150
|
+
static create({
|
|
151
|
+
callbackAble,
|
|
152
|
+
aIsUrgent
|
|
153
|
+
}) {
|
|
162
154
|
const queue = new TaskQueue(callbackAble, aIsUrgent);
|
|
163
155
|
queue.taskQueue = new PriorityQueue(aIsUrgent);
|
|
164
156
|
return queue;
|
|
165
157
|
}
|
|
166
158
|
pushTask(task) {
|
|
167
|
-
const
|
|
159
|
+
const taskQueue = this.taskQueue,
|
|
160
|
+
isScheduling = this.isScheduling;
|
|
168
161
|
taskQueue._add(task);
|
|
169
162
|
if (!isScheduling) {
|
|
170
163
|
this.callbackAble(this.scheduleTask.bind(this));
|
|
@@ -172,11 +165,14 @@ class TaskQueue {
|
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
167
|
scheduleTask() {
|
|
175
|
-
const
|
|
168
|
+
const taskQueue = this.taskQueue;
|
|
176
169
|
const fn = taskQueue.peek();
|
|
177
170
|
if (!fn) return this.isScheduling = false;
|
|
178
171
|
let info = fn() || {};
|
|
179
|
-
info =
|
|
172
|
+
info = {
|
|
173
|
+
...DefaultTaskControlReturn,
|
|
174
|
+
...info
|
|
175
|
+
};
|
|
180
176
|
if (info.finished) {
|
|
181
177
|
taskQueue.poll();
|
|
182
178
|
if (taskQueue.size() === 0) {
|
|
@@ -191,20 +187,21 @@ class TaskQueue {
|
|
|
191
187
|
}
|
|
192
188
|
}
|
|
193
189
|
|
|
194
|
-
var Keys = /* @__PURE__ */
|
|
190
|
+
var Keys = /* @__PURE__ */(Keys2 => {
|
|
195
191
|
Keys2["Iterator"] = "__AOYE_ITERATOR";
|
|
196
192
|
Keys2["Raw"] = "__AOYE_RAW";
|
|
197
193
|
Keys2["Meta"] = "__AOYE_META";
|
|
198
194
|
return Keys2;
|
|
199
195
|
})(Keys || {});
|
|
200
|
-
const IsStore = /* @__PURE__ */
|
|
196
|
+
const IsStore = /* @__PURE__ */Symbol("__AOYE_IS_STORE"),
|
|
197
|
+
StoreIgnoreKeys = /* @__PURE__ */Symbol("__AOYE_IGNORE_KEYS");
|
|
201
198
|
|
|
202
199
|
let channel = globalThis.MessageChannel ? new MessageChannel() : null;
|
|
203
200
|
if (globalThis.MessageChannel) {
|
|
204
201
|
channel = new MessageChannel();
|
|
205
202
|
}
|
|
206
203
|
let msgId = 0;
|
|
207
|
-
const macro =
|
|
204
|
+
const macro = fn => {
|
|
208
205
|
if (!channel) {
|
|
209
206
|
setTimeout(fn);
|
|
210
207
|
}
|
|
@@ -219,10 +216,10 @@ const macro = (fn) => {
|
|
|
219
216
|
channel.port1.postMessage(msgId++);
|
|
220
217
|
};
|
|
221
218
|
const p = Promise.resolve();
|
|
222
|
-
const micro =
|
|
219
|
+
const micro = cb => {
|
|
223
220
|
p.then(cb);
|
|
224
221
|
};
|
|
225
|
-
const toRaw =
|
|
222
|
+
const toRaw = a => {
|
|
226
223
|
if (typeof a === "object" && a !== null && a[Keys.Raw]) {
|
|
227
224
|
return toRaw(a[Keys.Raw]);
|
|
228
225
|
}
|
|
@@ -237,25 +234,31 @@ class Scheduler {
|
|
|
237
234
|
/** 记录 Set 或 BatchSet 产生的最后一个 Effect */
|
|
238
235
|
this.lastEffectItem = null;
|
|
239
236
|
}
|
|
237
|
+
static {
|
|
238
|
+
this.Sync = "__Sync_";
|
|
239
|
+
}
|
|
240
|
+
static {
|
|
241
|
+
this.Layout = "__Layout_";
|
|
242
|
+
}
|
|
243
|
+
static {
|
|
244
|
+
this.Micro = "__Micro_";
|
|
245
|
+
}
|
|
246
|
+
static {
|
|
247
|
+
this.Macro = "__Macro_";
|
|
248
|
+
}
|
|
240
249
|
endSet() {
|
|
241
|
-
var _a;
|
|
242
250
|
if (!this.firstEffectItem) return;
|
|
243
251
|
const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
|
|
244
252
|
this.firstEffectItem = null;
|
|
245
253
|
this.lastEffectItem = null;
|
|
246
|
-
|
|
254
|
+
this.onOneSetEffectsAdded?.(subQueue, this.effectQueue);
|
|
247
255
|
}
|
|
248
256
|
addEffect(effect) {
|
|
249
|
-
var _a;
|
|
250
257
|
const item = this.effectQueue.push(effect);
|
|
251
|
-
|
|
258
|
+
this.onEffectAdded?.(effect, item, this.effectQueue);
|
|
252
259
|
return item;
|
|
253
260
|
}
|
|
254
261
|
}
|
|
255
|
-
Scheduler.Sync = "__Sync_";
|
|
256
|
-
Scheduler.Layout = "__Layout_";
|
|
257
|
-
Scheduler.Micro = "__Micro_";
|
|
258
|
-
Scheduler.Macro = "__Macro_";
|
|
259
262
|
class SyncScheduler extends Scheduler {
|
|
260
263
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
261
264
|
subQueue.forEach((effect, item) => {
|
|
@@ -267,7 +270,10 @@ class SyncScheduler extends Scheduler {
|
|
|
267
270
|
class MicroScheduler extends Scheduler {
|
|
268
271
|
constructor() {
|
|
269
272
|
super(...arguments);
|
|
270
|
-
this.taskQueue = TaskQueue.create({
|
|
273
|
+
this.taskQueue = TaskQueue.create({
|
|
274
|
+
callbackAble: micro,
|
|
275
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
276
|
+
});
|
|
271
277
|
}
|
|
272
278
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
273
279
|
const task = () => {
|
|
@@ -287,7 +293,10 @@ class MicroScheduler extends Scheduler {
|
|
|
287
293
|
class MacroScheduler extends Scheduler {
|
|
288
294
|
constructor() {
|
|
289
295
|
super(...arguments);
|
|
290
|
-
this.taskQueue = TaskQueue.create({
|
|
296
|
+
this.taskQueue = TaskQueue.create({
|
|
297
|
+
callbackAble: macro,
|
|
298
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
299
|
+
});
|
|
291
300
|
}
|
|
292
301
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
293
302
|
const task = () => {
|
|
@@ -303,7 +312,10 @@ class MacroScheduler extends Scheduler {
|
|
|
303
312
|
class LayoutScheduler extends Scheduler {
|
|
304
313
|
constructor() {
|
|
305
314
|
super(...arguments);
|
|
306
|
-
this.taskQueue = TaskQueue.create({
|
|
315
|
+
this.taskQueue = TaskQueue.create({
|
|
316
|
+
callbackAble: macro,
|
|
317
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
318
|
+
});
|
|
307
319
|
}
|
|
308
320
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
309
321
|
const task = () => {
|
|
@@ -325,74 +337,6 @@ const _scheduler = {
|
|
|
325
337
|
globalThis["sche"] = _scheduler[Scheduler.Sync];
|
|
326
338
|
const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
|
|
327
339
|
|
|
328
|
-
var __defProp$2 = Object.defineProperty;
|
|
329
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
330
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
331
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
332
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
333
|
-
var __spreadValues$2 = (a, b) => {
|
|
334
|
-
for (var prop in b || (b = {}))
|
|
335
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
336
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
337
|
-
if (__getOwnPropSymbols$3)
|
|
338
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
339
|
-
if (__propIsEnum$3.call(b, prop))
|
|
340
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
341
|
-
}
|
|
342
|
-
return a;
|
|
343
|
-
};
|
|
344
|
-
const DefaultDFSOpt = {
|
|
345
|
-
isUp: false,
|
|
346
|
-
begin: null,
|
|
347
|
-
complete: null,
|
|
348
|
-
breakStack: [],
|
|
349
|
-
breakLine: null,
|
|
350
|
-
breakNode: null
|
|
351
|
-
};
|
|
352
|
-
function dfs(root, opt = {}) {
|
|
353
|
-
const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$2(__spreadValues$2({}, DefaultDFSOpt), opt);
|
|
354
|
-
let node = opt.breakNode || root;
|
|
355
|
-
let line = breakLine;
|
|
356
|
-
const listKey = isUp ? "recStart" : "emitStart";
|
|
357
|
-
const nodeKey = isUp ? "upstream" : "downstream";
|
|
358
|
-
const nextLineKey = isUp ? "nextRecLine" : "nextEmitLine";
|
|
359
|
-
const reverseNodeKey = isUp ? "downstream" : "upstream";
|
|
360
|
-
while (1) {
|
|
361
|
-
let notGoDeep = begin == null ? void 0 : begin({
|
|
362
|
-
node,
|
|
363
|
-
lineFromUp: line,
|
|
364
|
-
walkedLine: lineStack
|
|
365
|
-
});
|
|
366
|
-
lineStack.push(line);
|
|
367
|
-
line = node[listKey];
|
|
368
|
-
if (line && !notGoDeep) {
|
|
369
|
-
const firstChild = line[nodeKey];
|
|
370
|
-
node = firstChild;
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
while (1) {
|
|
374
|
-
const noGoSibling = complete == null ? void 0 : complete({
|
|
375
|
-
node,
|
|
376
|
-
lineToDeep: line,
|
|
377
|
-
walkedLine: lineStack,
|
|
378
|
-
notGoDeep
|
|
379
|
-
});
|
|
380
|
-
line = lineStack.pop();
|
|
381
|
-
if (node === root) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
notGoDeep = false;
|
|
385
|
-
const nextLine = line[nextLineKey];
|
|
386
|
-
if (!noGoSibling && nextLine) {
|
|
387
|
-
line = nextLine;
|
|
388
|
-
node = nextLine[nodeKey];
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
node = line[reverseNodeKey];
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
340
|
class Line {
|
|
397
341
|
constructor() {
|
|
398
342
|
/** 上游顶点 */
|
|
@@ -412,9 +356,17 @@ class Line {
|
|
|
412
356
|
this.nextOutLink = null;
|
|
413
357
|
}
|
|
414
358
|
static link(v1, v2) {
|
|
415
|
-
let
|
|
359
|
+
let emitEnd = v1.emitEnd,
|
|
360
|
+
recEnd = v2.recEnd,
|
|
361
|
+
recStart = v2.recStart,
|
|
362
|
+
noRecEnd = !recEnd,
|
|
363
|
+
head = {
|
|
364
|
+
nextRecLine: recStart
|
|
365
|
+
},
|
|
366
|
+
line;
|
|
416
367
|
recEnd = recEnd || head;
|
|
417
|
-
const
|
|
368
|
+
const _ref = recEnd || {},
|
|
369
|
+
nextRecLine = _ref.nextRecLine;
|
|
418
370
|
if (!nextRecLine) {
|
|
419
371
|
line = new Line();
|
|
420
372
|
Line.emit_line(v1, line);
|
|
@@ -445,7 +397,14 @@ class Line {
|
|
|
445
397
|
}
|
|
446
398
|
}
|
|
447
399
|
static unlink(line) {
|
|
448
|
-
let
|
|
400
|
+
let prevEmitLine = line.prevEmitLine,
|
|
401
|
+
nextEmitLine = line.nextEmitLine,
|
|
402
|
+
prevRecLine = line.prevRecLine,
|
|
403
|
+
nextRecLine = line.nextRecLine,
|
|
404
|
+
upstream = line.upstream,
|
|
405
|
+
downstream = line.downstream,
|
|
406
|
+
nextOutLink = line.nextOutLink,
|
|
407
|
+
prevOutLink = line.prevOutLink;
|
|
449
408
|
line.prevEmitLine = null;
|
|
450
409
|
line.nextEmitLine = null;
|
|
451
410
|
line.prevRecLine = null;
|
|
@@ -566,24 +525,46 @@ function unlinkSingleLine(line) {
|
|
|
566
525
|
}
|
|
567
526
|
function unlinkSingleRefedNode(delRoot) {
|
|
568
527
|
let toUnlink;
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
528
|
+
let node = delRoot,
|
|
529
|
+
i = -1,
|
|
530
|
+
parent;
|
|
531
|
+
const stack = [];
|
|
532
|
+
outer: do {
|
|
533
|
+
let noGoDeep = false;
|
|
534
|
+
doUnlink(toUnlink);
|
|
535
|
+
toUnlink = null;
|
|
536
|
+
noGoDeep = node.emitStart !== node.emitEnd;
|
|
537
|
+
const recStart = node.recStart;
|
|
538
|
+
if (recStart && !noGoDeep) {
|
|
539
|
+
stack[++i] = recStart;
|
|
540
|
+
parent = node;
|
|
541
|
+
node = recStart.upstream;
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
while (true) {
|
|
579
545
|
doUnlink(toUnlink);
|
|
580
546
|
toUnlink = null;
|
|
581
|
-
|
|
582
|
-
if (isSingleRefed) {
|
|
547
|
+
if (!noGoDeep) {
|
|
583
548
|
toUnlink = node.emitStart;
|
|
584
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
|
+
}
|
|
585
566
|
}
|
|
586
|
-
});
|
|
567
|
+
} while (true);
|
|
587
568
|
doUnlink(toUnlink);
|
|
588
569
|
}
|
|
589
570
|
function doUnlink(line) {
|
|
@@ -598,18 +579,41 @@ function dispose() {
|
|
|
598
579
|
const memoNext = toDel.nextRecLine;
|
|
599
580
|
const upstream = toDel.upstream;
|
|
600
581
|
if (upstream.state & State.IsScope) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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
|
+
}
|
|
610
614
|
}
|
|
611
615
|
}
|
|
612
|
-
});
|
|
616
|
+
} while (true);
|
|
613
617
|
} else {
|
|
614
618
|
unlinkSingleLine(toDel);
|
|
615
619
|
}
|
|
@@ -619,7 +623,6 @@ function dispose() {
|
|
|
619
623
|
doUnlink(this.emitStart);
|
|
620
624
|
}
|
|
621
625
|
function releaseScope(scope) {
|
|
622
|
-
var _a;
|
|
623
626
|
let outLink = scope.outLink;
|
|
624
627
|
while (outLink) {
|
|
625
628
|
const memoNext = outLink.nextOutLink;
|
|
@@ -627,7 +630,7 @@ function releaseScope(scope) {
|
|
|
627
630
|
outLink = memoNext;
|
|
628
631
|
}
|
|
629
632
|
scope.state |= State.ScopeAbort;
|
|
630
|
-
|
|
633
|
+
scope.clean?.();
|
|
631
634
|
scope.clean = null;
|
|
632
635
|
}
|
|
633
636
|
function clean(cb) {
|
|
@@ -647,82 +650,65 @@ function setPulling(pulling) {
|
|
|
647
650
|
G.PullingSignal = pulling;
|
|
648
651
|
}
|
|
649
652
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
const batch = new Batch();
|
|
670
|
-
|
|
671
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
672
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
673
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
674
|
-
var __objRest = (source, exclude) => {
|
|
675
|
-
var target = {};
|
|
676
|
-
for (var prop in source)
|
|
677
|
-
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
678
|
-
target[prop] = source[prop];
|
|
679
|
-
if (source != null && __getOwnPropSymbols$2)
|
|
680
|
-
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
681
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
682
|
-
target[prop] = source[prop];
|
|
683
|
-
}
|
|
684
|
-
return target;
|
|
685
|
-
};
|
|
686
|
-
const markDeep = (signal) => {
|
|
687
|
-
let level = 0, updatedSchedulers = /* @__PURE__ */ new Set();
|
|
688
|
-
dfs(signal, {
|
|
689
|
-
isUp: false,
|
|
690
|
-
begin: ({ node }) => {
|
|
691
|
-
if (node.isDisabled()) {
|
|
692
|
-
return true;
|
|
693
|
-
}
|
|
694
|
-
const inPullingArea = node.state & State.Pulling;
|
|
695
|
-
const Unknown = inPullingArea ? State.PullingUnknown : State.Unknown;
|
|
696
|
-
const isEffect = level > 0;
|
|
697
|
-
const isLeaf = !node.emitStart || node.emitStart.downstream === node.scope;
|
|
653
|
+
const markDeep = root => {
|
|
654
|
+
let node = root,
|
|
655
|
+
i = -1,
|
|
656
|
+
parent;
|
|
657
|
+
const stack = [];
|
|
658
|
+
outer: do {
|
|
659
|
+
let noGoDeep = false;
|
|
660
|
+
const state = node.state,
|
|
661
|
+
emitStart = node.emitStart,
|
|
662
|
+
scheduler = node.scheduler;
|
|
663
|
+
if (node.scope && node.scope.state & State.ScopeAbort ||
|
|
664
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
665
|
+
node.state & ScopeExecuted) {
|
|
666
|
+
noGoDeep = true;
|
|
667
|
+
} else {
|
|
668
|
+
const inPullingArea = state & State.Pulling;
|
|
669
|
+
const isEffect = parent !== void 0;
|
|
670
|
+
const isLeaf = !emitStart || emitStart.downstream === node.scope;
|
|
698
671
|
if (isEffect) {
|
|
699
|
-
node.state |= Unknown;
|
|
672
|
+
node.state |= inPullingArea ? State.PullingUnknown : State.Unknown;
|
|
700
673
|
} else if (!isLeaf) {
|
|
701
674
|
node.state |= State.Dirty;
|
|
702
675
|
}
|
|
703
|
-
if (isLeaf
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
instance.firstEffectItem
|
|
676
|
+
if (isLeaf) {
|
|
677
|
+
noGoDeep = true;
|
|
678
|
+
if (isEffect && !inPullingArea) {
|
|
679
|
+
const instance = _scheduler[scheduler];
|
|
680
|
+
const item = instance.addEffect(node);
|
|
681
|
+
instance.firstEffectItem ??= item;
|
|
682
|
+
instance.lastEffectItem = item;
|
|
709
683
|
}
|
|
710
|
-
instance.lastEffectItem = item;
|
|
711
|
-
updatedSchedulers.add(key);
|
|
712
684
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
685
|
+
}
|
|
686
|
+
if (emitStart && !noGoDeep) {
|
|
687
|
+
stack[++i] = emitStart;
|
|
688
|
+
parent = node;
|
|
689
|
+
node = emitStart.downstream;
|
|
690
|
+
noGoDeep = false;
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
while (true) {
|
|
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;
|
|
716
707
|
}
|
|
717
708
|
}
|
|
718
|
-
});
|
|
719
|
-
if (batch.inBatch()) return;
|
|
720
|
-
for (const key in _scheduler) {
|
|
721
|
-
const instance = _scheduler[key];
|
|
722
|
-
instance.endSet();
|
|
723
|
-
}
|
|
709
|
+
} while (true);
|
|
724
710
|
};
|
|
725
|
-
const pullingPostprocess =
|
|
711
|
+
const pullingPostprocess = node => {
|
|
726
712
|
let s = node.state;
|
|
727
713
|
s &= ~State.Pulling;
|
|
728
714
|
if (s & State.PullingUnknown) {
|
|
@@ -730,7 +716,7 @@ const pullingPostprocess = (node) => {
|
|
|
730
716
|
}
|
|
731
717
|
node.state = s;
|
|
732
718
|
};
|
|
733
|
-
|
|
719
|
+
class Signal {
|
|
734
720
|
constructor(nextValue, customPull) {
|
|
735
721
|
this.nextValue = nextValue;
|
|
736
722
|
this.customPull = customPull;
|
|
@@ -750,9 +736,17 @@ const _Signal = class _Signal {
|
|
|
750
736
|
/** 记录当前 effect 中 clean */
|
|
751
737
|
this.clean = null;
|
|
752
738
|
}
|
|
753
|
-
static
|
|
754
|
-
|
|
755
|
-
|
|
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);
|
|
756
750
|
s.pull = s.customPull || s.DEFAULT_PULL;
|
|
757
751
|
Object.assign(s, rest);
|
|
758
752
|
if (isScope) {
|
|
@@ -770,10 +764,9 @@ const _Signal = class _Signal {
|
|
|
770
764
|
* 递归拉取负责建立以来链
|
|
771
765
|
*/
|
|
772
766
|
pullRecurse(shouldLink = true) {
|
|
773
|
-
var _a, _b;
|
|
774
767
|
G.PullingRecurseDeep++;
|
|
775
768
|
const downstream = G.PullingSignal;
|
|
776
|
-
this.linkWhenPull(downstream);
|
|
769
|
+
this.linkWhenPull(downstream, shouldLink);
|
|
777
770
|
try {
|
|
778
771
|
if (this.version === G.version) {
|
|
779
772
|
return this.value;
|
|
@@ -781,7 +774,7 @@ const _Signal = class _Signal {
|
|
|
781
774
|
if (this.pull !== this.DEFAULT_PULL) this.recEnd = null;
|
|
782
775
|
this.state |= State.Pulling;
|
|
783
776
|
G.PullingSignal = this;
|
|
784
|
-
|
|
777
|
+
this.clean?.();
|
|
785
778
|
this.clean = null;
|
|
786
779
|
let v = this.pull();
|
|
787
780
|
if (this.state & State.IsScope && typeof v === "function") {
|
|
@@ -798,52 +791,63 @@ const _Signal = class _Signal {
|
|
|
798
791
|
} finally {
|
|
799
792
|
this.pull = this.customPull || this.DEFAULT_PULL;
|
|
800
793
|
pullingPostprocess(this);
|
|
801
|
-
const toDel =
|
|
794
|
+
const toDel = this.recEnd?.nextRecLine;
|
|
802
795
|
unlinkRecWithScope(toDel);
|
|
803
796
|
G.PullingSignal = downstream;
|
|
804
797
|
G.PullingRecurseDeep--;
|
|
805
798
|
}
|
|
806
799
|
}
|
|
807
|
-
linkWhenPull(downstream) {
|
|
800
|
+
linkWhenPull(downstream, shouldLink) {
|
|
808
801
|
const isScope = this.state & State.IsScope;
|
|
809
|
-
if (
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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)) {
|
|
818
814
|
Line.link(this, downstream);
|
|
819
815
|
}
|
|
820
816
|
}
|
|
821
817
|
pullDeep() {
|
|
822
818
|
const signal = this;
|
|
823
819
|
if (signal.state & DirtyState) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
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 {
|
|
830
829
|
node.state |= State.Pulling;
|
|
831
|
-
}
|
|
832
|
-
|
|
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) {
|
|
833
839
|
const isDirty = node.state & State.Dirty;
|
|
834
|
-
let currentClean =
|
|
835
|
-
if (
|
|
840
|
+
let currentClean = noGoDeep && !isDirty;
|
|
841
|
+
if (noGoDeep && node.state & State.Pulling) {
|
|
836
842
|
currentClean = true;
|
|
837
843
|
}
|
|
838
844
|
let noGoSibling = false;
|
|
839
|
-
const
|
|
840
|
-
const
|
|
845
|
+
const downstream2 = parent;
|
|
846
|
+
const isEmitter = node.pull === node.DEFAULT_PULL;
|
|
841
847
|
if (currentClean) ; else if (isDirty) {
|
|
842
|
-
if (
|
|
848
|
+
if (isEmitter && node.value !== node.nextValue) {
|
|
843
849
|
node.markDownStreamsDirty();
|
|
844
850
|
node.state &= ~State.Dirty;
|
|
845
|
-
node.state &= ~State.Pulling;
|
|
846
|
-
return;
|
|
847
851
|
} else {
|
|
848
852
|
const prevPulling = G.PullingSignal;
|
|
849
853
|
G.PullingSignal = downstream2;
|
|
@@ -859,14 +863,31 @@ const _Signal = class _Signal {
|
|
|
859
863
|
} else if (node.state & State.Unknown) {
|
|
860
864
|
node.state &= ~State.Unknown;
|
|
861
865
|
}
|
|
862
|
-
|
|
866
|
+
if (!isEmitter) {
|
|
867
|
+
node.version = G.version;
|
|
868
|
+
}
|
|
863
869
|
pullingPostprocess(node);
|
|
864
|
-
|
|
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
|
+
}
|
|
865
886
|
}
|
|
866
|
-
});
|
|
887
|
+
} while (true);
|
|
867
888
|
}
|
|
868
889
|
const downstream = G.PullingSignal;
|
|
869
|
-
this.linkWhenPull(downstream);
|
|
890
|
+
this.linkWhenPull(downstream, true);
|
|
870
891
|
return this.value;
|
|
871
892
|
}
|
|
872
893
|
get v() {
|
|
@@ -900,7 +921,18 @@ const _Signal = class _Signal {
|
|
|
900
921
|
this.nextValue = v;
|
|
901
922
|
this.pull = this.DEFAULT_PULL;
|
|
902
923
|
G.version++;
|
|
903
|
-
|
|
924
|
+
if (this.emitStart) {
|
|
925
|
+
markDeep(this);
|
|
926
|
+
if (batchDeep === 0) {
|
|
927
|
+
this.scheduleEffect();
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
scheduleEffect() {
|
|
932
|
+
for (const key in _scheduler) {
|
|
933
|
+
const instance = _scheduler[key];
|
|
934
|
+
instance.endSet();
|
|
935
|
+
}
|
|
904
936
|
}
|
|
905
937
|
/** 返回值为 true 表示已处理 */
|
|
906
938
|
runIfDirty() {
|
|
@@ -909,42 +941,32 @@ const _Signal = class _Signal {
|
|
|
909
941
|
isDisabled() {
|
|
910
942
|
return (
|
|
911
943
|
// scope 被取消
|
|
912
|
-
this.scope && this.scope.state & State.ScopeAbort ||
|
|
913
|
-
|
|
944
|
+
this.scope && this.scope.state & State.ScopeAbort ||
|
|
945
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
946
|
+
this.state & ScopeExecuted
|
|
914
947
|
);
|
|
915
948
|
}
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
949
|
+
}
|
|
950
|
+
let batchDeep = 0;
|
|
951
|
+
function batchStart() {
|
|
952
|
+
batchDeep++;
|
|
953
|
+
}
|
|
954
|
+
function batchEnd() {
|
|
955
|
+
if (--batchDeep) return;
|
|
956
|
+
for (const key in _scheduler) {
|
|
957
|
+
const instance = _scheduler[key];
|
|
958
|
+
instance.endSet();
|
|
959
|
+
}
|
|
960
|
+
}
|
|
919
961
|
|
|
920
|
-
var __defProp$1 = Object.defineProperty;
|
|
921
|
-
var __defProps = Object.defineProperties;
|
|
922
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
923
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
924
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
925
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
926
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
927
|
-
var __spreadValues$1 = (a, b) => {
|
|
928
|
-
for (var prop in b || (b = {}))
|
|
929
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
930
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
931
|
-
if (__getOwnPropSymbols$1)
|
|
932
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
933
|
-
if (__propIsEnum$1.call(b, prop))
|
|
934
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
935
|
-
}
|
|
936
|
-
return a;
|
|
937
|
-
};
|
|
938
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
939
962
|
const deepSignal = (target, scope, deep = true) => {
|
|
940
|
-
var _a;
|
|
941
963
|
const isObj = typeof target === "object" && target !== null;
|
|
942
964
|
if (!isObj || target[Keys.Raw]) return target;
|
|
943
965
|
const p = rawToProxy.get(target);
|
|
944
966
|
if (p) return p;
|
|
945
|
-
const cells = /* @__PURE__ */
|
|
967
|
+
const cells = /* @__PURE__ */new Map();
|
|
946
968
|
const targetIsArray = Array.isArray(target);
|
|
947
|
-
const targetIsStore = Boolean(
|
|
969
|
+
const targetIsStore = Boolean(target.constructor?.[IsStore]);
|
|
948
970
|
const meta = {
|
|
949
971
|
deep,
|
|
950
972
|
scope,
|
|
@@ -993,7 +1015,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
993
1015
|
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === "function") {
|
|
994
1016
|
return Reflect.set(obj, prop, value, receiver);
|
|
995
1017
|
}
|
|
996
|
-
|
|
1018
|
+
batchStart();
|
|
997
1019
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
998
1020
|
const cell = cells.get(prop);
|
|
999
1021
|
if (cell) {
|
|
@@ -1004,7 +1026,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
1004
1026
|
} else {
|
|
1005
1027
|
triggerIter(obj, prop, value, receiver);
|
|
1006
1028
|
}
|
|
1007
|
-
|
|
1029
|
+
batchEnd();
|
|
1008
1030
|
return success;
|
|
1009
1031
|
},
|
|
1010
1032
|
// 【核心修改】拦截 delete 操作
|
|
@@ -1033,10 +1055,14 @@ const shareSignal = (from, fromPath, to, toPath) => {
|
|
|
1033
1055
|
const toPaths = toPath.split(".");
|
|
1034
1056
|
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1035
1057
|
runWithPulling(() => {
|
|
1036
|
-
const
|
|
1058
|
+
const _getTargetAndKey = getTargetAndKey(from, formPaths),
|
|
1059
|
+
fromTarget = _getTargetAndKey.target,
|
|
1060
|
+
fromKey = _getTargetAndKey.key;
|
|
1037
1061
|
const val = fromTarget[fromKey];
|
|
1038
1062
|
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1039
|
-
const
|
|
1063
|
+
const _getTargetAndKey2 = getTargetAndKey(to, toPaths),
|
|
1064
|
+
toTarget = _getTargetAndKey2.target,
|
|
1065
|
+
toKey = _getTargetAndKey2.key;
|
|
1040
1066
|
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1041
1067
|
toTarget[Keys.Raw][toKey] = val;
|
|
1042
1068
|
}, null);
|
|
@@ -1055,13 +1081,16 @@ function getTargetAndKey(obj, paths) {
|
|
|
1055
1081
|
target = target[key];
|
|
1056
1082
|
}
|
|
1057
1083
|
}
|
|
1058
|
-
return {
|
|
1084
|
+
return {
|
|
1085
|
+
target,
|
|
1086
|
+
key
|
|
1087
|
+
};
|
|
1059
1088
|
}
|
|
1060
1089
|
function isIgnoreKey(ignores, key) {
|
|
1061
1090
|
if (typeof key !== "string") {
|
|
1062
1091
|
return ignores.includes(key);
|
|
1063
1092
|
}
|
|
1064
|
-
return ignores.some(
|
|
1093
|
+
return ignores.some(it => typeof it === "string" && key.startsWith(it));
|
|
1065
1094
|
}
|
|
1066
1095
|
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1067
1096
|
let s = cells.get(prop);
|
|
@@ -1090,18 +1119,18 @@ function triggerIter(obj, prop, value, receiver) {
|
|
|
1090
1119
|
}
|
|
1091
1120
|
}
|
|
1092
1121
|
const arrayMethodReWrites = {};
|
|
1093
|
-
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(
|
|
1094
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1095
|
-
|
|
1122
|
+
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(key => {
|
|
1123
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1124
|
+
batchStart();
|
|
1096
1125
|
const fn = Array.prototype[key];
|
|
1097
1126
|
const res = runWithPulling(() => fn.call(this, ...args), null);
|
|
1098
1127
|
this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
|
|
1099
|
-
|
|
1128
|
+
batchEnd();
|
|
1100
1129
|
return res;
|
|
1101
1130
|
};
|
|
1102
1131
|
});
|
|
1103
|
-
["includes", "indexOf", "lastIndexOf"].forEach(
|
|
1104
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1132
|
+
["includes", "indexOf", "lastIndexOf"].forEach(key => {
|
|
1133
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1105
1134
|
const fn = Array.prototype[key];
|
|
1106
1135
|
const that = toRaw(this);
|
|
1107
1136
|
let result = fn.call(that, ...args);
|
|
@@ -1121,14 +1150,15 @@ const arrayMethodReWrites = {};
|
|
|
1121
1150
|
return result;
|
|
1122
1151
|
};
|
|
1123
1152
|
});
|
|
1124
|
-
[Symbol.iterator, "values", "entries"].forEach(
|
|
1153
|
+
[Symbol.iterator, "values", "entries"].forEach(key => {
|
|
1125
1154
|
const isEntries = key === "entries";
|
|
1126
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1155
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1127
1156
|
const fn = Array.prototype[key];
|
|
1128
1157
|
const rawArray = toRaw(this);
|
|
1129
1158
|
const iter = fn.call(rawArray, ...args);
|
|
1130
1159
|
const meta = this[Keys.Meta];
|
|
1131
|
-
const
|
|
1160
|
+
const isDeep = meta.deep,
|
|
1161
|
+
scope = meta.scope;
|
|
1132
1162
|
if (isDeep) {
|
|
1133
1163
|
const rawNext = iter.next.bind(iter);
|
|
1134
1164
|
iter.next = () => {
|
|
@@ -1147,9 +1177,10 @@ const arrayMethodReWrites = {};
|
|
|
1147
1177
|
return iter;
|
|
1148
1178
|
};
|
|
1149
1179
|
});
|
|
1150
|
-
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1180
|
+
arrayMethodReWrites.filter = function (callback, thisArg) {
|
|
1151
1181
|
const meta = this[Keys.Meta];
|
|
1152
|
-
const
|
|
1182
|
+
const isDeep = meta.deep,
|
|
1183
|
+
scope = meta.scope;
|
|
1153
1184
|
const that = toRaw(this);
|
|
1154
1185
|
const result = [];
|
|
1155
1186
|
let resultIndex = 0;
|
|
@@ -1166,9 +1197,10 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
|
1166
1197
|
this[Keys.Iterator];
|
|
1167
1198
|
return result;
|
|
1168
1199
|
};
|
|
1169
|
-
arrayMethodReWrites.slice = function(start, end) {
|
|
1200
|
+
arrayMethodReWrites.slice = function (start, end) {
|
|
1170
1201
|
const meta = this[Keys.Meta];
|
|
1171
|
-
const
|
|
1202
|
+
const isDeep = meta.deep,
|
|
1203
|
+
scope = meta.scope;
|
|
1172
1204
|
const that = toRaw(this);
|
|
1173
1205
|
const len = that.length;
|
|
1174
1206
|
let k = start || 0;
|
|
@@ -1193,9 +1225,10 @@ arrayMethodReWrites.slice = function(start, end) {
|
|
|
1193
1225
|
this[Keys.Iterator];
|
|
1194
1226
|
return result;
|
|
1195
1227
|
};
|
|
1196
|
-
arrayMethodReWrites.toReversed = function() {
|
|
1228
|
+
arrayMethodReWrites.toReversed = function () {
|
|
1197
1229
|
const meta = this[Keys.Meta];
|
|
1198
|
-
const
|
|
1230
|
+
const isDeep = meta.deep,
|
|
1231
|
+
scope = meta.scope;
|
|
1199
1232
|
const that = toRaw(this);
|
|
1200
1233
|
const len = that.length;
|
|
1201
1234
|
const result = new Array(len);
|
|
@@ -1207,9 +1240,10 @@ arrayMethodReWrites.toReversed = function() {
|
|
|
1207
1240
|
this[Keys.Iterator];
|
|
1208
1241
|
return result;
|
|
1209
1242
|
};
|
|
1210
|
-
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1243
|
+
arrayMethodReWrites.toSpliced = function (start, deleteCount, ...items) {
|
|
1211
1244
|
const meta = this[Keys.Meta];
|
|
1212
|
-
const
|
|
1245
|
+
const isDeep = meta.deep,
|
|
1246
|
+
scope = meta.scope;
|
|
1213
1247
|
const that = toRaw(this);
|
|
1214
1248
|
const len = that.length;
|
|
1215
1249
|
let relativeStart = start >> 0;
|
|
@@ -1240,9 +1274,10 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
|
1240
1274
|
this[Keys.Iterator];
|
|
1241
1275
|
return result;
|
|
1242
1276
|
};
|
|
1243
|
-
arrayMethodReWrites.with = function(index, value) {
|
|
1277
|
+
arrayMethodReWrites.with = function (index, value) {
|
|
1244
1278
|
const meta = this[Keys.Meta];
|
|
1245
|
-
const
|
|
1279
|
+
const isDeep = meta.deep,
|
|
1280
|
+
scope = meta.scope;
|
|
1246
1281
|
const that = toRaw(this);
|
|
1247
1282
|
const len = that.length;
|
|
1248
1283
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1261,9 +1296,10 @@ arrayMethodReWrites.with = function(index, value) {
|
|
|
1261
1296
|
this[Keys.Iterator];
|
|
1262
1297
|
return result;
|
|
1263
1298
|
};
|
|
1264
|
-
arrayMethodReWrites.concat = function(...items) {
|
|
1299
|
+
arrayMethodReWrites.concat = function (...items) {
|
|
1265
1300
|
const meta = this[Keys.Meta];
|
|
1266
|
-
const
|
|
1301
|
+
const isDeep = meta.deep,
|
|
1302
|
+
scope = meta.scope;
|
|
1267
1303
|
const that = toRaw(this);
|
|
1268
1304
|
const selfLen = that.length;
|
|
1269
1305
|
let totalLength = selfLen;
|
|
@@ -1303,49 +1339,50 @@ const GetMethodConf = {
|
|
|
1303
1339
|
wrapReturn: false,
|
|
1304
1340
|
wrapArgs: 1
|
|
1305
1341
|
};
|
|
1306
|
-
[
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1342
|
+
[{
|
|
1343
|
+
key: "every",
|
|
1344
|
+
...GetMethodConf
|
|
1345
|
+
}, {
|
|
1346
|
+
key: "find",
|
|
1347
|
+
wrapReturn: true,
|
|
1348
|
+
...GetMethodConf
|
|
1349
|
+
}, {
|
|
1350
|
+
key: "findLast",
|
|
1351
|
+
...GetMethodConf,
|
|
1352
|
+
wrapReturn: true
|
|
1353
|
+
}, {
|
|
1354
|
+
key: "findIndex",
|
|
1355
|
+
...GetMethodConf
|
|
1356
|
+
}, {
|
|
1357
|
+
key: "findLastIndex",
|
|
1358
|
+
...GetMethodConf
|
|
1359
|
+
}, {
|
|
1360
|
+
key: "forEach",
|
|
1361
|
+
...GetMethodConf
|
|
1362
|
+
}, {
|
|
1363
|
+
key: "map",
|
|
1364
|
+
...GetMethodConf
|
|
1365
|
+
}, {
|
|
1366
|
+
key: "some",
|
|
1367
|
+
...GetMethodConf
|
|
1368
|
+
}, {
|
|
1369
|
+
key: "reduce",
|
|
1370
|
+
...GetMethodConf,
|
|
1371
|
+
wrapArgs: 2
|
|
1372
|
+
}, {
|
|
1373
|
+
key: "reduceRight",
|
|
1374
|
+
...GetMethodConf,
|
|
1375
|
+
wrapArgs: 2
|
|
1376
|
+
}].forEach(({
|
|
1377
|
+
key,
|
|
1378
|
+
wrapReturn,
|
|
1379
|
+
wrapArgs
|
|
1380
|
+
}) => {
|
|
1381
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1346
1382
|
const meta = this[Keys.Meta];
|
|
1347
1383
|
const fn = Array.prototype[key];
|
|
1348
|
-
const
|
|
1384
|
+
const isDeep = meta.deep,
|
|
1385
|
+
scope = meta.scope;
|
|
1349
1386
|
const that = toRaw(this);
|
|
1350
1387
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1351
1388
|
let result = fn.call(that, ...args);
|
|
@@ -1356,18 +1393,19 @@ const GetMethodConf = {
|
|
|
1356
1393
|
return result;
|
|
1357
1394
|
};
|
|
1358
1395
|
});
|
|
1359
|
-
arrayMethodReWrites.toSorted = function(...args) {
|
|
1396
|
+
arrayMethodReWrites.toSorted = function (...args) {
|
|
1360
1397
|
const fn = Array.prototype["toSorted"];
|
|
1361
1398
|
const meta = this[Keys.Meta];
|
|
1362
|
-
const
|
|
1399
|
+
const isDeep = meta.deep,
|
|
1400
|
+
scope = meta.scope;
|
|
1363
1401
|
const that = toRaw(this);
|
|
1364
1402
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1365
1403
|
let result = fn.call(that, ...args);
|
|
1366
1404
|
this[Keys.Iterator];
|
|
1367
|
-
return isDeep ? result.map(
|
|
1405
|
+
return isDeep ? result.map(it => deepSignal(it, scope)) : result;
|
|
1368
1406
|
};
|
|
1369
|
-
["join", "toString", "toLocaleString"].forEach(
|
|
1370
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1407
|
+
["join", "toString", "toLocaleString"].forEach(key => {
|
|
1408
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1371
1409
|
const fn = Array.prototype[key];
|
|
1372
1410
|
const that = toRaw(this);
|
|
1373
1411
|
const result = fn.call(that, ...args);
|
|
@@ -1377,7 +1415,7 @@ arrayMethodReWrites.toSorted = function(...args) {
|
|
|
1377
1415
|
});
|
|
1378
1416
|
function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
|
|
1379
1417
|
const callback = args[0];
|
|
1380
|
-
const wrapCb = function(...cbArgs) {
|
|
1418
|
+
const wrapCb = function (...cbArgs) {
|
|
1381
1419
|
if (isDeep) {
|
|
1382
1420
|
if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
|
|
1383
1421
|
if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
|
|
@@ -1396,6 +1434,15 @@ const _Store = class _Store {
|
|
|
1396
1434
|
_Store.Current = proxy;
|
|
1397
1435
|
return proxy;
|
|
1398
1436
|
}
|
|
1437
|
+
static {
|
|
1438
|
+
this[_b] = true;
|
|
1439
|
+
}
|
|
1440
|
+
static {
|
|
1441
|
+
this[_a] = ["ui", "raw"];
|
|
1442
|
+
}
|
|
1443
|
+
static {
|
|
1444
|
+
this.Current = null;
|
|
1445
|
+
}
|
|
1399
1446
|
static new(keyMap = {}, staticMap = {}) {
|
|
1400
1447
|
const parentStore = _Store.Current;
|
|
1401
1448
|
const child = new this();
|
|
@@ -1424,27 +1471,8 @@ const _Store = class _Store {
|
|
|
1424
1471
|
this.parent = null;
|
|
1425
1472
|
}
|
|
1426
1473
|
};
|
|
1427
|
-
_Store[_b] = true;
|
|
1428
|
-
_Store[_a] = ["ui", "raw"];
|
|
1429
|
-
_Store.Current = null;
|
|
1430
1474
|
let Store = _Store;
|
|
1431
1475
|
|
|
1432
|
-
var __defProp = Object.defineProperty;
|
|
1433
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1434
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1435
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1436
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1437
|
-
var __spreadValues = (a, b) => {
|
|
1438
|
-
for (var prop in b || (b = {}))
|
|
1439
|
-
if (__hasOwnProp.call(b, prop))
|
|
1440
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1441
|
-
if (__getOwnPropSymbols)
|
|
1442
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
1443
|
-
if (__propIsEnum.call(b, prop))
|
|
1444
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1445
|
-
}
|
|
1446
|
-
return a;
|
|
1447
|
-
};
|
|
1448
1476
|
const DefaultCustomSignalOpt = {
|
|
1449
1477
|
/** 三种模式
|
|
1450
1478
|
* 1. auto: 根据值类型自动判断 默认
|
|
@@ -1458,7 +1486,10 @@ const DefaultCustomSignalOpt = {
|
|
|
1458
1486
|
({
|
|
1459
1487
|
scheduler: Scheduler.Sync});
|
|
1460
1488
|
const $ = (init, opt = {}) => {
|
|
1461
|
-
opt =
|
|
1489
|
+
opt = {
|
|
1490
|
+
...DefaultCustomSignalOpt,
|
|
1491
|
+
...opt
|
|
1492
|
+
};
|
|
1462
1493
|
let intiValue, customPull;
|
|
1463
1494
|
if (typeof init === "function") {
|
|
1464
1495
|
intiValue = null;
|
|
@@ -1476,15 +1507,15 @@ const $ = (init, opt = {}) => {
|
|
|
1476
1507
|
return s;
|
|
1477
1508
|
};
|
|
1478
1509
|
const effect = (customPull, depOrOpt, opt) => {
|
|
1479
|
-
var _a;
|
|
1480
1510
|
const hasDep = Array.isArray(depOrOpt);
|
|
1481
1511
|
opt = hasDep ? opt || {} : depOrOpt || {};
|
|
1482
1512
|
if (!hasDep) {
|
|
1483
|
-
const s2 = Signal.create(null,
|
|
1513
|
+
const s2 = Signal.create(null, {
|
|
1484
1514
|
customPull,
|
|
1485
1515
|
scheduler: Scheduler.Sync,
|
|
1486
|
-
isScope: true
|
|
1487
|
-
|
|
1516
|
+
isScope: true,
|
|
1517
|
+
...opt
|
|
1518
|
+
});
|
|
1488
1519
|
s2.v;
|
|
1489
1520
|
const bound2 = dispose.bind(s2);
|
|
1490
1521
|
bound2.ins = s2;
|
|
@@ -1492,9 +1523,14 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1492
1523
|
}
|
|
1493
1524
|
let mounted = false;
|
|
1494
1525
|
const deps = depOrOpt;
|
|
1495
|
-
const immediate = deps.length === 0 ? true :
|
|
1496
|
-
const vs = Array.from({
|
|
1497
|
-
|
|
1526
|
+
const immediate = deps.length === 0 ? true : opt.immediate ?? true;
|
|
1527
|
+
const vs = Array.from({
|
|
1528
|
+
length: deps.length
|
|
1529
|
+
}, () => ({
|
|
1530
|
+
old: null,
|
|
1531
|
+
val: null
|
|
1532
|
+
}));
|
|
1533
|
+
const s = Signal.create(null, {
|
|
1498
1534
|
customPull() {
|
|
1499
1535
|
for (let i = 0; i < deps.length; i++) {
|
|
1500
1536
|
const value = deps[i].v;
|
|
@@ -1509,8 +1545,9 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1509
1545
|
mounted = true;
|
|
1510
1546
|
},
|
|
1511
1547
|
scheduler: Scheduler.Sync,
|
|
1512
|
-
isScope: true
|
|
1513
|
-
|
|
1548
|
+
isScope: true,
|
|
1549
|
+
...opt
|
|
1550
|
+
});
|
|
1514
1551
|
s.v;
|
|
1515
1552
|
const bound = dispose.bind(s);
|
|
1516
1553
|
bound.ins = s;
|
|
@@ -1536,17 +1573,20 @@ const scope = (...args) => {
|
|
|
1536
1573
|
bound.ins = s;
|
|
1537
1574
|
return bound;
|
|
1538
1575
|
};
|
|
1539
|
-
const customEffect =
|
|
1540
|
-
return (
|
|
1541
|
-
return effect(init,
|
|
1542
|
-
|
|
1576
|
+
const customEffect = opt => {
|
|
1577
|
+
return (init, innerOpt = {}) => {
|
|
1578
|
+
return effect(init, {
|
|
1579
|
+
...opt,
|
|
1580
|
+
...innerOpt
|
|
1581
|
+
});
|
|
1582
|
+
};
|
|
1543
1583
|
};
|
|
1544
|
-
const isSignal =
|
|
1584
|
+
const isSignal = value => {
|
|
1545
1585
|
return value instanceof Signal;
|
|
1546
1586
|
};
|
|
1547
|
-
const isScope =
|
|
1587
|
+
const isScope = value => {
|
|
1548
1588
|
return value instanceof Signal;
|
|
1549
1589
|
};
|
|
1550
1590
|
|
|
1551
|
-
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue,
|
|
1591
|
+
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batchEnd, batchStart, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal, toRaw };
|
|
1552
1592
|
//# sourceMappingURL=aoye.esm.js.map
|