aoye 0.0.21 → 0.0.22
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 +381 -315
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +380 -315
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +38 -43
- package/dist/index.umd.js +381 -315
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/aoye.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var bobeShared = require('bobe-shared');
|
|
4
4
|
|
|
5
|
-
const rawToProxy = /* @__PURE__ */
|
|
5
|
+
const rawToProxy = /* @__PURE__ */new WeakMap();
|
|
6
6
|
new bobeShared.BaseEvent();
|
|
7
7
|
const G = {
|
|
8
8
|
/** 原子 signal 更新次数 */
|
|
@@ -14,7 +14,7 @@ const G = {
|
|
|
14
14
|
/** 表示当前处于 pull 递归中 */
|
|
15
15
|
PullingRecurseDeep: 0
|
|
16
16
|
};
|
|
17
|
-
var State = /* @__PURE__ */
|
|
17
|
+
var State = /* @__PURE__ */(State2 => {
|
|
18
18
|
State2[State2["Clean"] = 0] = "Clean";
|
|
19
19
|
State2[State2["LinkScopeOnly"] = 256] = "LinkScopeOnly";
|
|
20
20
|
State2[State2["ScopeAbort"] = 128] = "ScopeAbort";
|
|
@@ -35,7 +35,12 @@ const leakI = (y, max) => y < 0 || y >= max ? null : y;
|
|
|
35
35
|
const getLeft = (x, max) => leakI(x * 2 + 1, max);
|
|
36
36
|
const getRight = (x, max) => leakI(x * 2 + 2, max);
|
|
37
37
|
const getParent = (x, max) => leakI(x - 1 >>> 1, max);
|
|
38
|
-
const exchange = (arr, i, j) =>
|
|
38
|
+
const exchange = (arr, i, j) => {
|
|
39
|
+
var _ref = [arr[j], arr[i]];
|
|
40
|
+
arr[i] = _ref[0];
|
|
41
|
+
arr[j] = _ref[1];
|
|
42
|
+
return _ref;
|
|
43
|
+
};
|
|
39
44
|
class PriorityQueue {
|
|
40
45
|
// 构造函数接受一个compare函数
|
|
41
46
|
// compare返回的-1, 0, 1决定元素是否优先被去除
|
|
@@ -87,11 +92,11 @@ class PriorityQueue {
|
|
|
87
92
|
this.goUp(this.arr, current, len);
|
|
88
93
|
}
|
|
89
94
|
add(...items) {
|
|
90
|
-
items.forEach(
|
|
95
|
+
items.forEach(it => this._add(it));
|
|
91
96
|
}
|
|
92
97
|
// 去除头元素并返回
|
|
93
98
|
poll() {
|
|
94
|
-
const
|
|
99
|
+
const arr = this.arr;
|
|
95
100
|
const len = this.size();
|
|
96
101
|
if (len <= 2) {
|
|
97
102
|
return arr.shift();
|
|
@@ -111,7 +116,7 @@ class PriorityQueue {
|
|
|
111
116
|
return this.arr.length;
|
|
112
117
|
}
|
|
113
118
|
logTree() {
|
|
114
|
-
const
|
|
119
|
+
const arr = this.arr;
|
|
115
120
|
let i = 0;
|
|
116
121
|
let j = 1;
|
|
117
122
|
let level = 0;
|
|
@@ -125,7 +130,7 @@ class PriorityQueue {
|
|
|
125
130
|
const last = Math.pow(2, matrix.length - 1);
|
|
126
131
|
const arrStr = JSON.stringify(last);
|
|
127
132
|
const halfLen = arrStr.length >>> 1;
|
|
128
|
-
matrix.forEach(
|
|
133
|
+
matrix.forEach(it => {
|
|
129
134
|
const str = JSON.stringify(it);
|
|
130
135
|
const halfIt = str.length >>> 1;
|
|
131
136
|
console.log(str.padStart(halfLen + halfIt, " "));
|
|
@@ -134,22 +139,6 @@ class PriorityQueue {
|
|
|
134
139
|
}
|
|
135
140
|
}
|
|
136
141
|
|
|
137
|
-
var __defProp$3 = Object.defineProperty;
|
|
138
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
139
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
140
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
141
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
142
|
-
var __spreadValues$3 = (a, b) => {
|
|
143
|
-
for (var prop in b || (b = {}))
|
|
144
|
-
if (__hasOwnProp$4.call(b, prop))
|
|
145
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
146
|
-
if (__getOwnPropSymbols$4)
|
|
147
|
-
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
148
|
-
if (__propIsEnum$4.call(b, prop))
|
|
149
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
150
|
-
}
|
|
151
|
-
return a;
|
|
152
|
-
};
|
|
153
142
|
const DefaultTaskControlReturn = {
|
|
154
143
|
finished: true,
|
|
155
144
|
startNewCallbackAble: true
|
|
@@ -160,13 +149,17 @@ class TaskQueue {
|
|
|
160
149
|
this.aIsUrgent = aIsUrgent;
|
|
161
150
|
this.isScheduling = false;
|
|
162
151
|
}
|
|
163
|
-
static create({
|
|
152
|
+
static create({
|
|
153
|
+
callbackAble,
|
|
154
|
+
aIsUrgent
|
|
155
|
+
}) {
|
|
164
156
|
const queue = new TaskQueue(callbackAble, aIsUrgent);
|
|
165
157
|
queue.taskQueue = new PriorityQueue(aIsUrgent);
|
|
166
158
|
return queue;
|
|
167
159
|
}
|
|
168
160
|
pushTask(task) {
|
|
169
|
-
const
|
|
161
|
+
const taskQueue = this.taskQueue,
|
|
162
|
+
isScheduling = this.isScheduling;
|
|
170
163
|
taskQueue._add(task);
|
|
171
164
|
if (!isScheduling) {
|
|
172
165
|
this.callbackAble(this.scheduleTask.bind(this));
|
|
@@ -174,11 +167,14 @@ class TaskQueue {
|
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
scheduleTask() {
|
|
177
|
-
const
|
|
170
|
+
const taskQueue = this.taskQueue;
|
|
178
171
|
const fn = taskQueue.peek();
|
|
179
172
|
if (!fn) return this.isScheduling = false;
|
|
180
173
|
let info = fn() || {};
|
|
181
|
-
info =
|
|
174
|
+
info = {
|
|
175
|
+
...DefaultTaskControlReturn,
|
|
176
|
+
...info
|
|
177
|
+
};
|
|
182
178
|
if (info.finished) {
|
|
183
179
|
taskQueue.poll();
|
|
184
180
|
if (taskQueue.size() === 0) {
|
|
@@ -193,20 +189,21 @@ class TaskQueue {
|
|
|
193
189
|
}
|
|
194
190
|
}
|
|
195
191
|
|
|
196
|
-
var Keys = /* @__PURE__ */
|
|
192
|
+
var Keys = /* @__PURE__ */(Keys2 => {
|
|
197
193
|
Keys2["Iterator"] = "__AOYE_ITERATOR";
|
|
198
194
|
Keys2["Raw"] = "__AOYE_RAW";
|
|
199
195
|
Keys2["Meta"] = "__AOYE_META";
|
|
200
196
|
return Keys2;
|
|
201
197
|
})(Keys || {});
|
|
202
|
-
const IsStore = /* @__PURE__ */
|
|
198
|
+
const IsStore = /* @__PURE__ */Symbol("__AOYE_IS_STORE"),
|
|
199
|
+
StoreIgnoreKeys = /* @__PURE__ */Symbol("__AOYE_IGNORE_KEYS");
|
|
203
200
|
|
|
204
201
|
let channel = globalThis.MessageChannel ? new MessageChannel() : null;
|
|
205
202
|
if (globalThis.MessageChannel) {
|
|
206
203
|
channel = new MessageChannel();
|
|
207
204
|
}
|
|
208
205
|
let msgId = 0;
|
|
209
|
-
const macro =
|
|
206
|
+
const macro = fn => {
|
|
210
207
|
if (!channel) {
|
|
211
208
|
setTimeout(fn);
|
|
212
209
|
}
|
|
@@ -221,10 +218,10 @@ const macro = (fn) => {
|
|
|
221
218
|
channel.port1.postMessage(msgId++);
|
|
222
219
|
};
|
|
223
220
|
const p = Promise.resolve();
|
|
224
|
-
const micro =
|
|
221
|
+
const micro = cb => {
|
|
225
222
|
p.then(cb);
|
|
226
223
|
};
|
|
227
|
-
const toRaw =
|
|
224
|
+
const toRaw = a => {
|
|
228
225
|
if (typeof a === "object" && a !== null && a[Keys.Raw]) {
|
|
229
226
|
return toRaw(a[Keys.Raw]);
|
|
230
227
|
}
|
|
@@ -239,25 +236,31 @@ class Scheduler {
|
|
|
239
236
|
/** 记录 Set 或 BatchSet 产生的最后一个 Effect */
|
|
240
237
|
this.lastEffectItem = null;
|
|
241
238
|
}
|
|
239
|
+
static {
|
|
240
|
+
this.Sync = "__Sync_";
|
|
241
|
+
}
|
|
242
|
+
static {
|
|
243
|
+
this.Layout = "__Layout_";
|
|
244
|
+
}
|
|
245
|
+
static {
|
|
246
|
+
this.Micro = "__Micro_";
|
|
247
|
+
}
|
|
248
|
+
static {
|
|
249
|
+
this.Macro = "__Macro_";
|
|
250
|
+
}
|
|
242
251
|
endSet() {
|
|
243
|
-
var _a;
|
|
244
252
|
if (!this.firstEffectItem) return;
|
|
245
253
|
const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
|
|
246
254
|
this.firstEffectItem = null;
|
|
247
255
|
this.lastEffectItem = null;
|
|
248
|
-
|
|
256
|
+
this.onOneSetEffectsAdded?.(subQueue, this.effectQueue);
|
|
249
257
|
}
|
|
250
258
|
addEffect(effect) {
|
|
251
|
-
var _a;
|
|
252
259
|
const item = this.effectQueue.push(effect);
|
|
253
|
-
|
|
260
|
+
this.onEffectAdded?.(effect, item, this.effectQueue);
|
|
254
261
|
return item;
|
|
255
262
|
}
|
|
256
263
|
}
|
|
257
|
-
Scheduler.Sync = "__Sync_";
|
|
258
|
-
Scheduler.Layout = "__Layout_";
|
|
259
|
-
Scheduler.Micro = "__Micro_";
|
|
260
|
-
Scheduler.Macro = "__Macro_";
|
|
261
264
|
class SyncScheduler extends Scheduler {
|
|
262
265
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
263
266
|
subQueue.forEach((effect, item) => {
|
|
@@ -269,7 +272,10 @@ class SyncScheduler extends Scheduler {
|
|
|
269
272
|
class MicroScheduler extends Scheduler {
|
|
270
273
|
constructor() {
|
|
271
274
|
super(...arguments);
|
|
272
|
-
this.taskQueue = TaskQueue.create({
|
|
275
|
+
this.taskQueue = TaskQueue.create({
|
|
276
|
+
callbackAble: micro,
|
|
277
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
278
|
+
});
|
|
273
279
|
}
|
|
274
280
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
275
281
|
const task = () => {
|
|
@@ -289,7 +295,10 @@ class MicroScheduler extends Scheduler {
|
|
|
289
295
|
class MacroScheduler extends Scheduler {
|
|
290
296
|
constructor() {
|
|
291
297
|
super(...arguments);
|
|
292
|
-
this.taskQueue = TaskQueue.create({
|
|
298
|
+
this.taskQueue = TaskQueue.create({
|
|
299
|
+
callbackAble: macro,
|
|
300
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
301
|
+
});
|
|
293
302
|
}
|
|
294
303
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
295
304
|
const task = () => {
|
|
@@ -305,7 +314,10 @@ class MacroScheduler extends Scheduler {
|
|
|
305
314
|
class LayoutScheduler extends Scheduler {
|
|
306
315
|
constructor() {
|
|
307
316
|
super(...arguments);
|
|
308
|
-
this.taskQueue = TaskQueue.create({
|
|
317
|
+
this.taskQueue = TaskQueue.create({
|
|
318
|
+
callbackAble: macro,
|
|
319
|
+
aIsUrgent: (a, b) => a.time < b.time
|
|
320
|
+
});
|
|
309
321
|
}
|
|
310
322
|
onOneSetEffectsAdded(subQueue, queue) {
|
|
311
323
|
const task = () => {
|
|
@@ -327,22 +339,6 @@ const _scheduler = {
|
|
|
327
339
|
globalThis["sche"] = _scheduler[Scheduler.Sync];
|
|
328
340
|
const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
|
|
329
341
|
|
|
330
|
-
var __defProp$2 = Object.defineProperty;
|
|
331
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
332
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
333
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
334
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
335
|
-
var __spreadValues$2 = (a, b) => {
|
|
336
|
-
for (var prop in b || (b = {}))
|
|
337
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
338
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
339
|
-
if (__getOwnPropSymbols$3)
|
|
340
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
341
|
-
if (__propIsEnum$3.call(b, prop))
|
|
342
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
343
|
-
}
|
|
344
|
-
return a;
|
|
345
|
-
};
|
|
346
342
|
const DefaultDFSOpt = {
|
|
347
343
|
isUp: false,
|
|
348
344
|
begin: null,
|
|
@@ -352,15 +348,23 @@ const DefaultDFSOpt = {
|
|
|
352
348
|
breakNode: null
|
|
353
349
|
};
|
|
354
350
|
function dfs(root, opt = {}) {
|
|
355
|
-
const
|
|
351
|
+
const _DefaultDFSOpt$opt = {
|
|
352
|
+
...DefaultDFSOpt,
|
|
353
|
+
...opt
|
|
354
|
+
},
|
|
355
|
+
isUp = _DefaultDFSOpt$opt.isUp,
|
|
356
|
+
begin = _DefaultDFSOpt$opt.begin,
|
|
357
|
+
complete = _DefaultDFSOpt$opt.complete,
|
|
358
|
+
lineStack = _DefaultDFSOpt$opt.breakStack,
|
|
359
|
+
breakLine = _DefaultDFSOpt$opt.breakLine;
|
|
356
360
|
let node = opt.breakNode || root;
|
|
357
361
|
let line = breakLine;
|
|
358
362
|
const listKey = isUp ? "recStart" : "emitStart";
|
|
359
363
|
const nodeKey = isUp ? "upstream" : "downstream";
|
|
360
364
|
const nextLineKey = isUp ? "nextRecLine" : "nextEmitLine";
|
|
361
365
|
const reverseNodeKey = isUp ? "downstream" : "upstream";
|
|
362
|
-
while (
|
|
363
|
-
let notGoDeep = begin
|
|
366
|
+
while (true) {
|
|
367
|
+
let notGoDeep = begin?.({
|
|
364
368
|
node,
|
|
365
369
|
lineFromUp: line,
|
|
366
370
|
walkedLine: lineStack
|
|
@@ -372,8 +376,8 @@ function dfs(root, opt = {}) {
|
|
|
372
376
|
node = firstChild;
|
|
373
377
|
continue;
|
|
374
378
|
}
|
|
375
|
-
while (
|
|
376
|
-
const noGoSibling = complete
|
|
379
|
+
while (true) {
|
|
380
|
+
const noGoSibling = complete?.({
|
|
377
381
|
node,
|
|
378
382
|
lineToDeep: line,
|
|
379
383
|
walkedLine: lineStack,
|
|
@@ -414,9 +418,17 @@ class Line {
|
|
|
414
418
|
this.nextOutLink = null;
|
|
415
419
|
}
|
|
416
420
|
static link(v1, v2) {
|
|
417
|
-
let
|
|
421
|
+
let emitEnd = v1.emitEnd,
|
|
422
|
+
recEnd = v2.recEnd,
|
|
423
|
+
recStart = v2.recStart,
|
|
424
|
+
noRecEnd = !recEnd,
|
|
425
|
+
head = {
|
|
426
|
+
nextRecLine: recStart
|
|
427
|
+
},
|
|
428
|
+
line;
|
|
418
429
|
recEnd = recEnd || head;
|
|
419
|
-
const
|
|
430
|
+
const _ref = recEnd || {},
|
|
431
|
+
nextRecLine = _ref.nextRecLine;
|
|
420
432
|
if (!nextRecLine) {
|
|
421
433
|
line = new Line();
|
|
422
434
|
Line.emit_line(v1, line);
|
|
@@ -447,7 +459,14 @@ class Line {
|
|
|
447
459
|
}
|
|
448
460
|
}
|
|
449
461
|
static unlink(line) {
|
|
450
|
-
let
|
|
462
|
+
let prevEmitLine = line.prevEmitLine,
|
|
463
|
+
nextEmitLine = line.nextEmitLine,
|
|
464
|
+
prevRecLine = line.prevRecLine,
|
|
465
|
+
nextRecLine = line.nextRecLine,
|
|
466
|
+
upstream = line.upstream,
|
|
467
|
+
downstream = line.downstream,
|
|
468
|
+
nextOutLink = line.nextOutLink,
|
|
469
|
+
prevOutLink = line.prevOutLink;
|
|
451
470
|
line.prevEmitLine = null;
|
|
452
471
|
line.nextEmitLine = null;
|
|
453
472
|
line.prevRecLine = null;
|
|
@@ -570,14 +589,19 @@ function unlinkSingleRefedNode(delRoot) {
|
|
|
570
589
|
let toUnlink;
|
|
571
590
|
dfs(delRoot, {
|
|
572
591
|
isUp: true,
|
|
573
|
-
begin: ({
|
|
592
|
+
begin: ({
|
|
593
|
+
node
|
|
594
|
+
}) => {
|
|
574
595
|
doUnlink(toUnlink);
|
|
575
596
|
toUnlink = null;
|
|
576
597
|
if (node.emitStart !== node.emitEnd) {
|
|
577
598
|
return true;
|
|
578
599
|
}
|
|
579
600
|
},
|
|
580
|
-
complete: ({
|
|
601
|
+
complete: ({
|
|
602
|
+
node,
|
|
603
|
+
notGoDeep
|
|
604
|
+
}) => {
|
|
581
605
|
doUnlink(toUnlink);
|
|
582
606
|
toUnlink = null;
|
|
583
607
|
const isSingleRefed = !notGoDeep;
|
|
@@ -602,10 +626,15 @@ function dispose() {
|
|
|
602
626
|
if (upstream.state & State.IsScope) {
|
|
603
627
|
dfs(upstream, {
|
|
604
628
|
isUp: true,
|
|
605
|
-
begin: ({
|
|
629
|
+
begin: ({
|
|
630
|
+
node
|
|
631
|
+
}) => {
|
|
606
632
|
if ((node.state & State.IsScope) === 0 || node.state & ScopeAbort) return true;
|
|
607
633
|
},
|
|
608
|
-
complete: ({
|
|
634
|
+
complete: ({
|
|
635
|
+
node: scope,
|
|
636
|
+
notGoDeep
|
|
637
|
+
}) => {
|
|
609
638
|
const shouldAbort = !notGoDeep;
|
|
610
639
|
if (shouldAbort) {
|
|
611
640
|
releaseScope(scope);
|
|
@@ -621,7 +650,6 @@ function dispose() {
|
|
|
621
650
|
doUnlink(this.emitStart);
|
|
622
651
|
}
|
|
623
652
|
function releaseScope(scope) {
|
|
624
|
-
var _a;
|
|
625
653
|
let outLink = scope.outLink;
|
|
626
654
|
while (outLink) {
|
|
627
655
|
const memoNext = outLink.nextOutLink;
|
|
@@ -629,7 +657,7 @@ function releaseScope(scope) {
|
|
|
629
657
|
outLink = memoNext;
|
|
630
658
|
}
|
|
631
659
|
scope.state |= State.ScopeAbort;
|
|
632
|
-
|
|
660
|
+
scope.clean?.();
|
|
633
661
|
scope.clean = null;
|
|
634
662
|
}
|
|
635
663
|
function clean(cb) {
|
|
@@ -649,82 +677,65 @@ function setPulling(pulling) {
|
|
|
649
677
|
G.PullingSignal = pulling;
|
|
650
678
|
}
|
|
651
679
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
const batch = new Batch();
|
|
672
|
-
|
|
673
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
674
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
675
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
676
|
-
var __objRest = (source, exclude) => {
|
|
677
|
-
var target = {};
|
|
678
|
-
for (var prop in source)
|
|
679
|
-
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
680
|
-
target[prop] = source[prop];
|
|
681
|
-
if (source != null && __getOwnPropSymbols$2)
|
|
682
|
-
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
683
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
684
|
-
target[prop] = source[prop];
|
|
685
|
-
}
|
|
686
|
-
return target;
|
|
687
|
-
};
|
|
688
|
-
const markDeep = (signal) => {
|
|
689
|
-
let level = 0, updatedSchedulers = /* @__PURE__ */ new Set();
|
|
690
|
-
dfs(signal, {
|
|
691
|
-
isUp: false,
|
|
692
|
-
begin: ({ node }) => {
|
|
693
|
-
if (node.isDisabled()) {
|
|
694
|
-
return true;
|
|
695
|
-
}
|
|
696
|
-
const inPullingArea = node.state & State.Pulling;
|
|
697
|
-
const Unknown = inPullingArea ? State.PullingUnknown : State.Unknown;
|
|
698
|
-
const isEffect = level > 0;
|
|
699
|
-
const isLeaf = !node.emitStart || node.emitStart.downstream === node.scope;
|
|
680
|
+
const markDeep = root => {
|
|
681
|
+
let node = root,
|
|
682
|
+
i = -1,
|
|
683
|
+
parent;
|
|
684
|
+
const stack = [];
|
|
685
|
+
outer: do {
|
|
686
|
+
let noGoDeep = false;
|
|
687
|
+
const state = node.state,
|
|
688
|
+
emitStart = node.emitStart,
|
|
689
|
+
scheduler = node.scheduler;
|
|
690
|
+
if (node.scope && node.scope.state & State.ScopeAbort ||
|
|
691
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
692
|
+
node.state & ScopeExecuted) {
|
|
693
|
+
noGoDeep = true;
|
|
694
|
+
} else {
|
|
695
|
+
const inPullingArea = state & State.Pulling;
|
|
696
|
+
const isEffect = parent !== void 0;
|
|
697
|
+
const isLeaf = !emitStart || emitStart.downstream === node.scope;
|
|
700
698
|
if (isEffect) {
|
|
701
|
-
node.state |= Unknown;
|
|
699
|
+
node.state |= inPullingArea ? State.PullingUnknown : State.Unknown;
|
|
702
700
|
} else if (!isLeaf) {
|
|
703
701
|
node.state |= State.Dirty;
|
|
704
702
|
}
|
|
705
|
-
if (isLeaf
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
instance.firstEffectItem
|
|
703
|
+
if (isLeaf) {
|
|
704
|
+
noGoDeep = true;
|
|
705
|
+
if (isEffect && !inPullingArea) {
|
|
706
|
+
const instance = _scheduler[scheduler];
|
|
707
|
+
const item = instance.addEffect(node);
|
|
708
|
+
instance.firstEffectItem ??= item;
|
|
709
|
+
instance.lastEffectItem = item;
|
|
711
710
|
}
|
|
712
|
-
instance.lastEffectItem = item;
|
|
713
|
-
updatedSchedulers.add(key);
|
|
714
711
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
712
|
+
}
|
|
713
|
+
if (emitStart && !noGoDeep) {
|
|
714
|
+
stack[++i] = emitStart;
|
|
715
|
+
parent = node;
|
|
716
|
+
node = emitStart.downstream;
|
|
717
|
+
noGoDeep = false;
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
while (true) {
|
|
721
|
+
if (i === -1) {
|
|
722
|
+
break outer;
|
|
723
|
+
}
|
|
724
|
+
const backLine = stack[i];
|
|
725
|
+
const nextLine = backLine.nextEmitLine;
|
|
726
|
+
if (nextLine) {
|
|
727
|
+
node = nextLine.downstream;
|
|
728
|
+
stack[i] = nextLine;
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
731
|
+
node = parent;
|
|
732
|
+
if (--i !== -1) {
|
|
733
|
+
parent = stack[i].upstream;
|
|
718
734
|
}
|
|
719
735
|
}
|
|
720
|
-
});
|
|
721
|
-
if (batch.inBatch()) return;
|
|
722
|
-
for (const key in _scheduler) {
|
|
723
|
-
const instance = _scheduler[key];
|
|
724
|
-
instance.endSet();
|
|
725
|
-
}
|
|
736
|
+
} while (true);
|
|
726
737
|
};
|
|
727
|
-
const pullingPostprocess =
|
|
738
|
+
const pullingPostprocess = node => {
|
|
728
739
|
let s = node.state;
|
|
729
740
|
s &= ~State.Pulling;
|
|
730
741
|
if (s & State.PullingUnknown) {
|
|
@@ -732,7 +743,7 @@ const pullingPostprocess = (node) => {
|
|
|
732
743
|
}
|
|
733
744
|
node.state = s;
|
|
734
745
|
};
|
|
735
|
-
|
|
746
|
+
class Signal {
|
|
736
747
|
constructor(nextValue, customPull) {
|
|
737
748
|
this.nextValue = nextValue;
|
|
738
749
|
this.customPull = customPull;
|
|
@@ -752,9 +763,17 @@ const _Signal = class _Signal {
|
|
|
752
763
|
/** 记录当前 effect 中 clean */
|
|
753
764
|
this.clean = null;
|
|
754
765
|
}
|
|
755
|
-
static
|
|
756
|
-
|
|
757
|
-
|
|
766
|
+
static {
|
|
767
|
+
this.Pulling = null;
|
|
768
|
+
}
|
|
769
|
+
static create(nextValue, {
|
|
770
|
+
customPull,
|
|
771
|
+
isScope,
|
|
772
|
+
scope,
|
|
773
|
+
immediate,
|
|
774
|
+
...rest
|
|
775
|
+
}) {
|
|
776
|
+
const s = new Signal(nextValue, customPull);
|
|
758
777
|
s.pull = s.customPull || s.DEFAULT_PULL;
|
|
759
778
|
Object.assign(s, rest);
|
|
760
779
|
if (isScope) {
|
|
@@ -772,10 +791,9 @@ const _Signal = class _Signal {
|
|
|
772
791
|
* 递归拉取负责建立以来链
|
|
773
792
|
*/
|
|
774
793
|
pullRecurse(shouldLink = true) {
|
|
775
|
-
var _a, _b;
|
|
776
794
|
G.PullingRecurseDeep++;
|
|
777
795
|
const downstream = G.PullingSignal;
|
|
778
|
-
this.linkWhenPull(downstream);
|
|
796
|
+
this.linkWhenPull(downstream, shouldLink);
|
|
779
797
|
try {
|
|
780
798
|
if (this.version === G.version) {
|
|
781
799
|
return this.value;
|
|
@@ -783,7 +801,7 @@ const _Signal = class _Signal {
|
|
|
783
801
|
if (this.pull !== this.DEFAULT_PULL) this.recEnd = null;
|
|
784
802
|
this.state |= State.Pulling;
|
|
785
803
|
G.PullingSignal = this;
|
|
786
|
-
|
|
804
|
+
this.clean?.();
|
|
787
805
|
this.clean = null;
|
|
788
806
|
let v = this.pull();
|
|
789
807
|
if (this.state & State.IsScope && typeof v === "function") {
|
|
@@ -800,52 +818,63 @@ const _Signal = class _Signal {
|
|
|
800
818
|
} finally {
|
|
801
819
|
this.pull = this.customPull || this.DEFAULT_PULL;
|
|
802
820
|
pullingPostprocess(this);
|
|
803
|
-
const toDel =
|
|
821
|
+
const toDel = this.recEnd?.nextRecLine;
|
|
804
822
|
unlinkRecWithScope(toDel);
|
|
805
823
|
G.PullingSignal = downstream;
|
|
806
824
|
G.PullingRecurseDeep--;
|
|
807
825
|
}
|
|
808
826
|
}
|
|
809
|
-
linkWhenPull(downstream) {
|
|
827
|
+
linkWhenPull(downstream, shouldLink) {
|
|
810
828
|
const isScope = this.state & State.IsScope;
|
|
811
|
-
if (
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
829
|
+
if (
|
|
830
|
+
// 2. 有下游
|
|
831
|
+
downstream && shouldLink && (
|
|
832
|
+
// 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
833
|
+
(downstream.state & State.LinkScopeOnly) === 0 || isScope) && (
|
|
834
|
+
/**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
|
|
835
|
+
* 发生在 outEffect(() => scope(() => innerEffect(), null))
|
|
836
|
+
* 虽然通过 scope 让 innerEffect 被管理,
|
|
837
|
+
* 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
|
|
838
|
+
* 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
|
|
839
|
+
*/
|
|
840
|
+
!isScope || !this.emitStart)) {
|
|
820
841
|
Line.link(this, downstream);
|
|
821
842
|
}
|
|
822
843
|
}
|
|
823
844
|
pullDeep() {
|
|
824
845
|
const signal = this;
|
|
825
846
|
if (signal.state & DirtyState) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
847
|
+
let node = signal,
|
|
848
|
+
i = -1,
|
|
849
|
+
parent;
|
|
850
|
+
const stack = [];
|
|
851
|
+
outer: do {
|
|
852
|
+
let noGoDeep = false;
|
|
853
|
+
if (node.state & (State.Pulling | State.Dirty) || (node.state & DirtyState) === 0 || node.isDisabled()) {
|
|
854
|
+
noGoDeep = true;
|
|
855
|
+
} else {
|
|
832
856
|
node.state |= State.Pulling;
|
|
833
|
-
}
|
|
834
|
-
|
|
857
|
+
}
|
|
858
|
+
const recStart = node.recStart;
|
|
859
|
+
if (recStart && !noGoDeep) {
|
|
860
|
+
stack[++i] = recStart;
|
|
861
|
+
parent = node;
|
|
862
|
+
node = recStart.upstream;
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
while (true) {
|
|
835
866
|
const isDirty = node.state & State.Dirty;
|
|
836
|
-
let currentClean =
|
|
837
|
-
if (
|
|
867
|
+
let currentClean = noGoDeep && !isDirty;
|
|
868
|
+
if (noGoDeep && node.state & State.Pulling) {
|
|
838
869
|
currentClean = true;
|
|
839
870
|
}
|
|
840
871
|
let noGoSibling = false;
|
|
841
|
-
const
|
|
842
|
-
const
|
|
872
|
+
const downstream2 = parent;
|
|
873
|
+
const isEmitter = node.pull === node.DEFAULT_PULL;
|
|
843
874
|
if (currentClean) ; else if (isDirty) {
|
|
844
|
-
if (
|
|
875
|
+
if (isEmitter && node.value !== node.nextValue) {
|
|
845
876
|
node.markDownStreamsDirty();
|
|
846
877
|
node.state &= ~State.Dirty;
|
|
847
|
-
node.state &= ~State.Pulling;
|
|
848
|
-
return;
|
|
849
878
|
} else {
|
|
850
879
|
const prevPulling = G.PullingSignal;
|
|
851
880
|
G.PullingSignal = downstream2;
|
|
@@ -861,14 +890,31 @@ const _Signal = class _Signal {
|
|
|
861
890
|
} else if (node.state & State.Unknown) {
|
|
862
891
|
node.state &= ~State.Unknown;
|
|
863
892
|
}
|
|
864
|
-
|
|
893
|
+
if (!isEmitter) {
|
|
894
|
+
node.version = G.version;
|
|
895
|
+
}
|
|
865
896
|
pullingPostprocess(node);
|
|
866
|
-
|
|
897
|
+
noGoDeep = false;
|
|
898
|
+
if (i === -1) {
|
|
899
|
+
break outer;
|
|
900
|
+
}
|
|
901
|
+
const backLine = stack[i];
|
|
902
|
+
const nextLine = backLine.nextRecLine;
|
|
903
|
+
if (!noGoSibling && nextLine) {
|
|
904
|
+
node = nextLine.upstream;
|
|
905
|
+
stack[i] = nextLine;
|
|
906
|
+
break;
|
|
907
|
+
} else {
|
|
908
|
+
node = parent;
|
|
909
|
+
if (--i !== -1) {
|
|
910
|
+
parent = stack[i].downstream;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
867
913
|
}
|
|
868
|
-
});
|
|
914
|
+
} while (true);
|
|
869
915
|
}
|
|
870
916
|
const downstream = G.PullingSignal;
|
|
871
|
-
this.linkWhenPull(downstream);
|
|
917
|
+
this.linkWhenPull(downstream, true);
|
|
872
918
|
return this.value;
|
|
873
919
|
}
|
|
874
920
|
get v() {
|
|
@@ -902,7 +948,18 @@ const _Signal = class _Signal {
|
|
|
902
948
|
this.nextValue = v;
|
|
903
949
|
this.pull = this.DEFAULT_PULL;
|
|
904
950
|
G.version++;
|
|
905
|
-
|
|
951
|
+
if (this.emitStart) {
|
|
952
|
+
markDeep(this);
|
|
953
|
+
if (batchDeep === 0) {
|
|
954
|
+
this.scheduleEffect();
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
scheduleEffect() {
|
|
959
|
+
for (const key in _scheduler) {
|
|
960
|
+
const instance = _scheduler[key];
|
|
961
|
+
instance.endSet();
|
|
962
|
+
}
|
|
906
963
|
}
|
|
907
964
|
/** 返回值为 true 表示已处理 */
|
|
908
965
|
runIfDirty() {
|
|
@@ -911,42 +968,32 @@ const _Signal = class _Signal {
|
|
|
911
968
|
isDisabled() {
|
|
912
969
|
return (
|
|
913
970
|
// scope 被取消
|
|
914
|
-
this.scope && this.scope.state & State.ScopeAbort ||
|
|
915
|
-
|
|
971
|
+
this.scope && this.scope.state & State.ScopeAbort ||
|
|
972
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
973
|
+
this.state & ScopeExecuted
|
|
916
974
|
);
|
|
917
975
|
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
|
|
976
|
+
}
|
|
977
|
+
let batchDeep = 0;
|
|
978
|
+
function batchStart() {
|
|
979
|
+
batchDeep++;
|
|
980
|
+
}
|
|
981
|
+
function batchEnd() {
|
|
982
|
+
if (--batchDeep) return;
|
|
983
|
+
for (const key in _scheduler) {
|
|
984
|
+
const instance = _scheduler[key];
|
|
985
|
+
instance.endSet();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
921
988
|
|
|
922
|
-
var __defProp$1 = Object.defineProperty;
|
|
923
|
-
var __defProps = Object.defineProperties;
|
|
924
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
925
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
926
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
927
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
928
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
929
|
-
var __spreadValues$1 = (a, b) => {
|
|
930
|
-
for (var prop in b || (b = {}))
|
|
931
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
932
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
933
|
-
if (__getOwnPropSymbols$1)
|
|
934
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
935
|
-
if (__propIsEnum$1.call(b, prop))
|
|
936
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
937
|
-
}
|
|
938
|
-
return a;
|
|
939
|
-
};
|
|
940
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
941
989
|
const deepSignal = (target, scope, deep = true) => {
|
|
942
|
-
var _a;
|
|
943
990
|
const isObj = typeof target === "object" && target !== null;
|
|
944
991
|
if (!isObj || target[Keys.Raw]) return target;
|
|
945
992
|
const p = rawToProxy.get(target);
|
|
946
993
|
if (p) return p;
|
|
947
|
-
const cells = /* @__PURE__ */
|
|
994
|
+
const cells = /* @__PURE__ */new Map();
|
|
948
995
|
const targetIsArray = Array.isArray(target);
|
|
949
|
-
const targetIsStore = Boolean(
|
|
996
|
+
const targetIsStore = Boolean(target.constructor?.[IsStore]);
|
|
950
997
|
const meta = {
|
|
951
998
|
deep,
|
|
952
999
|
scope,
|
|
@@ -995,7 +1042,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
995
1042
|
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === "function") {
|
|
996
1043
|
return Reflect.set(obj, prop, value, receiver);
|
|
997
1044
|
}
|
|
998
|
-
|
|
1045
|
+
batchStart();
|
|
999
1046
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
1000
1047
|
const cell = cells.get(prop);
|
|
1001
1048
|
if (cell) {
|
|
@@ -1006,7 +1053,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
1006
1053
|
} else {
|
|
1007
1054
|
triggerIter(obj, prop, value, receiver);
|
|
1008
1055
|
}
|
|
1009
|
-
|
|
1056
|
+
batchEnd();
|
|
1010
1057
|
return success;
|
|
1011
1058
|
},
|
|
1012
1059
|
// 【核心修改】拦截 delete 操作
|
|
@@ -1035,10 +1082,14 @@ const shareSignal = (from, fromPath, to, toPath) => {
|
|
|
1035
1082
|
const toPaths = toPath.split(".");
|
|
1036
1083
|
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1037
1084
|
runWithPulling(() => {
|
|
1038
|
-
const
|
|
1085
|
+
const _getTargetAndKey = getTargetAndKey(from, formPaths),
|
|
1086
|
+
fromTarget = _getTargetAndKey.target,
|
|
1087
|
+
fromKey = _getTargetAndKey.key;
|
|
1039
1088
|
const val = fromTarget[fromKey];
|
|
1040
1089
|
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1041
|
-
const
|
|
1090
|
+
const _getTargetAndKey2 = getTargetAndKey(to, toPaths),
|
|
1091
|
+
toTarget = _getTargetAndKey2.target,
|
|
1092
|
+
toKey = _getTargetAndKey2.key;
|
|
1042
1093
|
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1043
1094
|
toTarget[Keys.Raw][toKey] = val;
|
|
1044
1095
|
}, null);
|
|
@@ -1057,13 +1108,16 @@ function getTargetAndKey(obj, paths) {
|
|
|
1057
1108
|
target = target[key];
|
|
1058
1109
|
}
|
|
1059
1110
|
}
|
|
1060
|
-
return {
|
|
1111
|
+
return {
|
|
1112
|
+
target,
|
|
1113
|
+
key
|
|
1114
|
+
};
|
|
1061
1115
|
}
|
|
1062
1116
|
function isIgnoreKey(ignores, key) {
|
|
1063
1117
|
if (typeof key !== "string") {
|
|
1064
1118
|
return ignores.includes(key);
|
|
1065
1119
|
}
|
|
1066
|
-
return ignores.some(
|
|
1120
|
+
return ignores.some(it => typeof it === "string" && key.startsWith(it));
|
|
1067
1121
|
}
|
|
1068
1122
|
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1069
1123
|
let s = cells.get(prop);
|
|
@@ -1092,18 +1146,18 @@ function triggerIter(obj, prop, value, receiver) {
|
|
|
1092
1146
|
}
|
|
1093
1147
|
}
|
|
1094
1148
|
const arrayMethodReWrites = {};
|
|
1095
|
-
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(
|
|
1096
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1097
|
-
|
|
1149
|
+
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(key => {
|
|
1150
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1151
|
+
batchStart();
|
|
1098
1152
|
const fn = Array.prototype[key];
|
|
1099
1153
|
const res = runWithPulling(() => fn.call(this, ...args), null);
|
|
1100
1154
|
this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
|
|
1101
|
-
|
|
1155
|
+
batchEnd();
|
|
1102
1156
|
return res;
|
|
1103
1157
|
};
|
|
1104
1158
|
});
|
|
1105
|
-
["includes", "indexOf", "lastIndexOf"].forEach(
|
|
1106
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1159
|
+
["includes", "indexOf", "lastIndexOf"].forEach(key => {
|
|
1160
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1107
1161
|
const fn = Array.prototype[key];
|
|
1108
1162
|
const that = toRaw(this);
|
|
1109
1163
|
let result = fn.call(that, ...args);
|
|
@@ -1123,14 +1177,15 @@ const arrayMethodReWrites = {};
|
|
|
1123
1177
|
return result;
|
|
1124
1178
|
};
|
|
1125
1179
|
});
|
|
1126
|
-
[Symbol.iterator, "values", "entries"].forEach(
|
|
1180
|
+
[Symbol.iterator, "values", "entries"].forEach(key => {
|
|
1127
1181
|
const isEntries = key === "entries";
|
|
1128
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1182
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1129
1183
|
const fn = Array.prototype[key];
|
|
1130
1184
|
const rawArray = toRaw(this);
|
|
1131
1185
|
const iter = fn.call(rawArray, ...args);
|
|
1132
1186
|
const meta = this[Keys.Meta];
|
|
1133
|
-
const
|
|
1187
|
+
const isDeep = meta.deep,
|
|
1188
|
+
scope = meta.scope;
|
|
1134
1189
|
if (isDeep) {
|
|
1135
1190
|
const rawNext = iter.next.bind(iter);
|
|
1136
1191
|
iter.next = () => {
|
|
@@ -1149,9 +1204,10 @@ const arrayMethodReWrites = {};
|
|
|
1149
1204
|
return iter;
|
|
1150
1205
|
};
|
|
1151
1206
|
});
|
|
1152
|
-
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1207
|
+
arrayMethodReWrites.filter = function (callback, thisArg) {
|
|
1153
1208
|
const meta = this[Keys.Meta];
|
|
1154
|
-
const
|
|
1209
|
+
const isDeep = meta.deep,
|
|
1210
|
+
scope = meta.scope;
|
|
1155
1211
|
const that = toRaw(this);
|
|
1156
1212
|
const result = [];
|
|
1157
1213
|
let resultIndex = 0;
|
|
@@ -1168,9 +1224,10 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
|
1168
1224
|
this[Keys.Iterator];
|
|
1169
1225
|
return result;
|
|
1170
1226
|
};
|
|
1171
|
-
arrayMethodReWrites.slice = function(start, end) {
|
|
1227
|
+
arrayMethodReWrites.slice = function (start, end) {
|
|
1172
1228
|
const meta = this[Keys.Meta];
|
|
1173
|
-
const
|
|
1229
|
+
const isDeep = meta.deep,
|
|
1230
|
+
scope = meta.scope;
|
|
1174
1231
|
const that = toRaw(this);
|
|
1175
1232
|
const len = that.length;
|
|
1176
1233
|
let k = start || 0;
|
|
@@ -1195,9 +1252,10 @@ arrayMethodReWrites.slice = function(start, end) {
|
|
|
1195
1252
|
this[Keys.Iterator];
|
|
1196
1253
|
return result;
|
|
1197
1254
|
};
|
|
1198
|
-
arrayMethodReWrites.toReversed = function() {
|
|
1255
|
+
arrayMethodReWrites.toReversed = function () {
|
|
1199
1256
|
const meta = this[Keys.Meta];
|
|
1200
|
-
const
|
|
1257
|
+
const isDeep = meta.deep,
|
|
1258
|
+
scope = meta.scope;
|
|
1201
1259
|
const that = toRaw(this);
|
|
1202
1260
|
const len = that.length;
|
|
1203
1261
|
const result = new Array(len);
|
|
@@ -1209,9 +1267,10 @@ arrayMethodReWrites.toReversed = function() {
|
|
|
1209
1267
|
this[Keys.Iterator];
|
|
1210
1268
|
return result;
|
|
1211
1269
|
};
|
|
1212
|
-
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1270
|
+
arrayMethodReWrites.toSpliced = function (start, deleteCount, ...items) {
|
|
1213
1271
|
const meta = this[Keys.Meta];
|
|
1214
|
-
const
|
|
1272
|
+
const isDeep = meta.deep,
|
|
1273
|
+
scope = meta.scope;
|
|
1215
1274
|
const that = toRaw(this);
|
|
1216
1275
|
const len = that.length;
|
|
1217
1276
|
let relativeStart = start >> 0;
|
|
@@ -1242,9 +1301,10 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
|
1242
1301
|
this[Keys.Iterator];
|
|
1243
1302
|
return result;
|
|
1244
1303
|
};
|
|
1245
|
-
arrayMethodReWrites.with = function(index, value) {
|
|
1304
|
+
arrayMethodReWrites.with = function (index, value) {
|
|
1246
1305
|
const meta = this[Keys.Meta];
|
|
1247
|
-
const
|
|
1306
|
+
const isDeep = meta.deep,
|
|
1307
|
+
scope = meta.scope;
|
|
1248
1308
|
const that = toRaw(this);
|
|
1249
1309
|
const len = that.length;
|
|
1250
1310
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1263,9 +1323,10 @@ arrayMethodReWrites.with = function(index, value) {
|
|
|
1263
1323
|
this[Keys.Iterator];
|
|
1264
1324
|
return result;
|
|
1265
1325
|
};
|
|
1266
|
-
arrayMethodReWrites.concat = function(...items) {
|
|
1326
|
+
arrayMethodReWrites.concat = function (...items) {
|
|
1267
1327
|
const meta = this[Keys.Meta];
|
|
1268
|
-
const
|
|
1328
|
+
const isDeep = meta.deep,
|
|
1329
|
+
scope = meta.scope;
|
|
1269
1330
|
const that = toRaw(this);
|
|
1270
1331
|
const selfLen = that.length;
|
|
1271
1332
|
let totalLength = selfLen;
|
|
@@ -1305,49 +1366,50 @@ const GetMethodConf = {
|
|
|
1305
1366
|
wrapReturn: false,
|
|
1306
1367
|
wrapArgs: 1
|
|
1307
1368
|
};
|
|
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
|
-
|
|
1346
|
-
|
|
1347
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1369
|
+
[{
|
|
1370
|
+
key: "every",
|
|
1371
|
+
...GetMethodConf
|
|
1372
|
+
}, {
|
|
1373
|
+
key: "find",
|
|
1374
|
+
wrapReturn: true,
|
|
1375
|
+
...GetMethodConf
|
|
1376
|
+
}, {
|
|
1377
|
+
key: "findLast",
|
|
1378
|
+
...GetMethodConf,
|
|
1379
|
+
wrapReturn: true
|
|
1380
|
+
}, {
|
|
1381
|
+
key: "findIndex",
|
|
1382
|
+
...GetMethodConf
|
|
1383
|
+
}, {
|
|
1384
|
+
key: "findLastIndex",
|
|
1385
|
+
...GetMethodConf
|
|
1386
|
+
}, {
|
|
1387
|
+
key: "forEach",
|
|
1388
|
+
...GetMethodConf
|
|
1389
|
+
}, {
|
|
1390
|
+
key: "map",
|
|
1391
|
+
...GetMethodConf
|
|
1392
|
+
}, {
|
|
1393
|
+
key: "some",
|
|
1394
|
+
...GetMethodConf
|
|
1395
|
+
}, {
|
|
1396
|
+
key: "reduce",
|
|
1397
|
+
...GetMethodConf,
|
|
1398
|
+
wrapArgs: 2
|
|
1399
|
+
}, {
|
|
1400
|
+
key: "reduceRight",
|
|
1401
|
+
...GetMethodConf,
|
|
1402
|
+
wrapArgs: 2
|
|
1403
|
+
}].forEach(({
|
|
1404
|
+
key,
|
|
1405
|
+
wrapReturn,
|
|
1406
|
+
wrapArgs
|
|
1407
|
+
}) => {
|
|
1408
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1348
1409
|
const meta = this[Keys.Meta];
|
|
1349
1410
|
const fn = Array.prototype[key];
|
|
1350
|
-
const
|
|
1411
|
+
const isDeep = meta.deep,
|
|
1412
|
+
scope = meta.scope;
|
|
1351
1413
|
const that = toRaw(this);
|
|
1352
1414
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1353
1415
|
let result = fn.call(that, ...args);
|
|
@@ -1358,18 +1420,19 @@ const GetMethodConf = {
|
|
|
1358
1420
|
return result;
|
|
1359
1421
|
};
|
|
1360
1422
|
});
|
|
1361
|
-
arrayMethodReWrites.toSorted = function(...args) {
|
|
1423
|
+
arrayMethodReWrites.toSorted = function (...args) {
|
|
1362
1424
|
const fn = Array.prototype["toSorted"];
|
|
1363
1425
|
const meta = this[Keys.Meta];
|
|
1364
|
-
const
|
|
1426
|
+
const isDeep = meta.deep,
|
|
1427
|
+
scope = meta.scope;
|
|
1365
1428
|
const that = toRaw(this);
|
|
1366
1429
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1367
1430
|
let result = fn.call(that, ...args);
|
|
1368
1431
|
this[Keys.Iterator];
|
|
1369
|
-
return isDeep ? result.map(
|
|
1432
|
+
return isDeep ? result.map(it => deepSignal(it, scope)) : result;
|
|
1370
1433
|
};
|
|
1371
|
-
["join", "toString", "toLocaleString"].forEach(
|
|
1372
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1434
|
+
["join", "toString", "toLocaleString"].forEach(key => {
|
|
1435
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1373
1436
|
const fn = Array.prototype[key];
|
|
1374
1437
|
const that = toRaw(this);
|
|
1375
1438
|
const result = fn.call(that, ...args);
|
|
@@ -1379,7 +1442,7 @@ arrayMethodReWrites.toSorted = function(...args) {
|
|
|
1379
1442
|
});
|
|
1380
1443
|
function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
|
|
1381
1444
|
const callback = args[0];
|
|
1382
|
-
const wrapCb = function(...cbArgs) {
|
|
1445
|
+
const wrapCb = function (...cbArgs) {
|
|
1383
1446
|
if (isDeep) {
|
|
1384
1447
|
if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
|
|
1385
1448
|
if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
|
|
@@ -1398,6 +1461,15 @@ const _Store = class _Store {
|
|
|
1398
1461
|
_Store.Current = proxy;
|
|
1399
1462
|
return proxy;
|
|
1400
1463
|
}
|
|
1464
|
+
static {
|
|
1465
|
+
this[_b] = true;
|
|
1466
|
+
}
|
|
1467
|
+
static {
|
|
1468
|
+
this[_a] = ["ui", "raw"];
|
|
1469
|
+
}
|
|
1470
|
+
static {
|
|
1471
|
+
this.Current = null;
|
|
1472
|
+
}
|
|
1401
1473
|
static new(keyMap = {}, staticMap = {}) {
|
|
1402
1474
|
const parentStore = _Store.Current;
|
|
1403
1475
|
const child = new this();
|
|
@@ -1426,27 +1498,8 @@ const _Store = class _Store {
|
|
|
1426
1498
|
this.parent = null;
|
|
1427
1499
|
}
|
|
1428
1500
|
};
|
|
1429
|
-
_Store[_b] = true;
|
|
1430
|
-
_Store[_a] = ["ui", "raw"];
|
|
1431
|
-
_Store.Current = null;
|
|
1432
1501
|
let Store = _Store;
|
|
1433
1502
|
|
|
1434
|
-
var __defProp = Object.defineProperty;
|
|
1435
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1436
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1437
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1438
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1439
|
-
var __spreadValues = (a, b) => {
|
|
1440
|
-
for (var prop in b || (b = {}))
|
|
1441
|
-
if (__hasOwnProp.call(b, prop))
|
|
1442
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1443
|
-
if (__getOwnPropSymbols)
|
|
1444
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
1445
|
-
if (__propIsEnum.call(b, prop))
|
|
1446
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1447
|
-
}
|
|
1448
|
-
return a;
|
|
1449
|
-
};
|
|
1450
1503
|
const DefaultCustomSignalOpt = {
|
|
1451
1504
|
/** 三种模式
|
|
1452
1505
|
* 1. auto: 根据值类型自动判断 默认
|
|
@@ -1460,7 +1513,10 @@ const DefaultCustomSignalOpt = {
|
|
|
1460
1513
|
({
|
|
1461
1514
|
scheduler: Scheduler.Sync});
|
|
1462
1515
|
const $ = (init, opt = {}) => {
|
|
1463
|
-
opt =
|
|
1516
|
+
opt = {
|
|
1517
|
+
...DefaultCustomSignalOpt,
|
|
1518
|
+
...opt
|
|
1519
|
+
};
|
|
1464
1520
|
let intiValue, customPull;
|
|
1465
1521
|
if (typeof init === "function") {
|
|
1466
1522
|
intiValue = null;
|
|
@@ -1478,15 +1534,15 @@ const $ = (init, opt = {}) => {
|
|
|
1478
1534
|
return s;
|
|
1479
1535
|
};
|
|
1480
1536
|
const effect = (customPull, depOrOpt, opt) => {
|
|
1481
|
-
var _a;
|
|
1482
1537
|
const hasDep = Array.isArray(depOrOpt);
|
|
1483
1538
|
opt = hasDep ? opt || {} : depOrOpt || {};
|
|
1484
1539
|
if (!hasDep) {
|
|
1485
|
-
const s2 = Signal.create(null,
|
|
1540
|
+
const s2 = Signal.create(null, {
|
|
1486
1541
|
customPull,
|
|
1487
1542
|
scheduler: Scheduler.Sync,
|
|
1488
|
-
isScope: true
|
|
1489
|
-
|
|
1543
|
+
isScope: true,
|
|
1544
|
+
...opt
|
|
1545
|
+
});
|
|
1490
1546
|
s2.v;
|
|
1491
1547
|
const bound2 = dispose.bind(s2);
|
|
1492
1548
|
bound2.ins = s2;
|
|
@@ -1494,9 +1550,14 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1494
1550
|
}
|
|
1495
1551
|
let mounted = false;
|
|
1496
1552
|
const deps = depOrOpt;
|
|
1497
|
-
const immediate = deps.length === 0 ? true :
|
|
1498
|
-
const vs = Array.from({
|
|
1499
|
-
|
|
1553
|
+
const immediate = deps.length === 0 ? true : opt.immediate ?? true;
|
|
1554
|
+
const vs = Array.from({
|
|
1555
|
+
length: deps.length
|
|
1556
|
+
}, () => ({
|
|
1557
|
+
old: null,
|
|
1558
|
+
val: null
|
|
1559
|
+
}));
|
|
1560
|
+
const s = Signal.create(null, {
|
|
1500
1561
|
customPull() {
|
|
1501
1562
|
for (let i = 0; i < deps.length; i++) {
|
|
1502
1563
|
const value = deps[i].v;
|
|
@@ -1511,8 +1572,9 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1511
1572
|
mounted = true;
|
|
1512
1573
|
},
|
|
1513
1574
|
scheduler: Scheduler.Sync,
|
|
1514
|
-
isScope: true
|
|
1515
|
-
|
|
1575
|
+
isScope: true,
|
|
1576
|
+
...opt
|
|
1577
|
+
});
|
|
1516
1578
|
s.v;
|
|
1517
1579
|
const bound = dispose.bind(s);
|
|
1518
1580
|
bound.ins = s;
|
|
@@ -1538,15 +1600,18 @@ const scope = (...args) => {
|
|
|
1538
1600
|
bound.ins = s;
|
|
1539
1601
|
return bound;
|
|
1540
1602
|
};
|
|
1541
|
-
const customEffect =
|
|
1542
|
-
return (
|
|
1543
|
-
return effect(init,
|
|
1544
|
-
|
|
1603
|
+
const customEffect = opt => {
|
|
1604
|
+
return (init, innerOpt = {}) => {
|
|
1605
|
+
return effect(init, {
|
|
1606
|
+
...opt,
|
|
1607
|
+
...innerOpt
|
|
1608
|
+
});
|
|
1609
|
+
};
|
|
1545
1610
|
};
|
|
1546
|
-
const isSignal =
|
|
1611
|
+
const isSignal = value => {
|
|
1547
1612
|
return value instanceof Signal;
|
|
1548
1613
|
};
|
|
1549
|
-
const isScope =
|
|
1614
|
+
const isScope = value => {
|
|
1550
1615
|
return value instanceof Signal;
|
|
1551
1616
|
};
|
|
1552
1617
|
|
|
@@ -1558,7 +1623,8 @@ exports.Signal = Signal;
|
|
|
1558
1623
|
exports.Store = Store;
|
|
1559
1624
|
exports.StoreIgnoreKeys = StoreIgnoreKeys;
|
|
1560
1625
|
exports.TaskQueue = TaskQueue;
|
|
1561
|
-
exports.
|
|
1626
|
+
exports.batchEnd = batchEnd;
|
|
1627
|
+
exports.batchStart = batchStart;
|
|
1562
1628
|
exports.clean = clean;
|
|
1563
1629
|
exports.customEffect = customEffect;
|
|
1564
1630
|
exports.deepSignal = deepSignal;
|