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