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.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,22 +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
340
|
const DefaultDFSOpt = {
|
|
345
341
|
isUp: false,
|
|
346
342
|
begin: null,
|
|
@@ -350,15 +346,23 @@ const DefaultDFSOpt = {
|
|
|
350
346
|
breakNode: null
|
|
351
347
|
};
|
|
352
348
|
function dfs(root, opt = {}) {
|
|
353
|
-
const
|
|
349
|
+
const _DefaultDFSOpt$opt = {
|
|
350
|
+
...DefaultDFSOpt,
|
|
351
|
+
...opt
|
|
352
|
+
},
|
|
353
|
+
isUp = _DefaultDFSOpt$opt.isUp,
|
|
354
|
+
begin = _DefaultDFSOpt$opt.begin,
|
|
355
|
+
complete = _DefaultDFSOpt$opt.complete,
|
|
356
|
+
lineStack = _DefaultDFSOpt$opt.breakStack,
|
|
357
|
+
breakLine = _DefaultDFSOpt$opt.breakLine;
|
|
354
358
|
let node = opt.breakNode || root;
|
|
355
359
|
let line = breakLine;
|
|
356
360
|
const listKey = isUp ? "recStart" : "emitStart";
|
|
357
361
|
const nodeKey = isUp ? "upstream" : "downstream";
|
|
358
362
|
const nextLineKey = isUp ? "nextRecLine" : "nextEmitLine";
|
|
359
363
|
const reverseNodeKey = isUp ? "downstream" : "upstream";
|
|
360
|
-
while (
|
|
361
|
-
let notGoDeep = begin
|
|
364
|
+
while (true) {
|
|
365
|
+
let notGoDeep = begin?.({
|
|
362
366
|
node,
|
|
363
367
|
lineFromUp: line,
|
|
364
368
|
walkedLine: lineStack
|
|
@@ -370,8 +374,8 @@ function dfs(root, opt = {}) {
|
|
|
370
374
|
node = firstChild;
|
|
371
375
|
continue;
|
|
372
376
|
}
|
|
373
|
-
while (
|
|
374
|
-
const noGoSibling = complete
|
|
377
|
+
while (true) {
|
|
378
|
+
const noGoSibling = complete?.({
|
|
375
379
|
node,
|
|
376
380
|
lineToDeep: line,
|
|
377
381
|
walkedLine: lineStack,
|
|
@@ -412,9 +416,17 @@ class Line {
|
|
|
412
416
|
this.nextOutLink = null;
|
|
413
417
|
}
|
|
414
418
|
static link(v1, v2) {
|
|
415
|
-
let
|
|
419
|
+
let emitEnd = v1.emitEnd,
|
|
420
|
+
recEnd = v2.recEnd,
|
|
421
|
+
recStart = v2.recStart,
|
|
422
|
+
noRecEnd = !recEnd,
|
|
423
|
+
head = {
|
|
424
|
+
nextRecLine: recStart
|
|
425
|
+
},
|
|
426
|
+
line;
|
|
416
427
|
recEnd = recEnd || head;
|
|
417
|
-
const
|
|
428
|
+
const _ref = recEnd || {},
|
|
429
|
+
nextRecLine = _ref.nextRecLine;
|
|
418
430
|
if (!nextRecLine) {
|
|
419
431
|
line = new Line();
|
|
420
432
|
Line.emit_line(v1, line);
|
|
@@ -445,7 +457,14 @@ class Line {
|
|
|
445
457
|
}
|
|
446
458
|
}
|
|
447
459
|
static unlink(line) {
|
|
448
|
-
let
|
|
460
|
+
let prevEmitLine = line.prevEmitLine,
|
|
461
|
+
nextEmitLine = line.nextEmitLine,
|
|
462
|
+
prevRecLine = line.prevRecLine,
|
|
463
|
+
nextRecLine = line.nextRecLine,
|
|
464
|
+
upstream = line.upstream,
|
|
465
|
+
downstream = line.downstream,
|
|
466
|
+
nextOutLink = line.nextOutLink,
|
|
467
|
+
prevOutLink = line.prevOutLink;
|
|
449
468
|
line.prevEmitLine = null;
|
|
450
469
|
line.nextEmitLine = null;
|
|
451
470
|
line.prevRecLine = null;
|
|
@@ -568,14 +587,19 @@ function unlinkSingleRefedNode(delRoot) {
|
|
|
568
587
|
let toUnlink;
|
|
569
588
|
dfs(delRoot, {
|
|
570
589
|
isUp: true,
|
|
571
|
-
begin: ({
|
|
590
|
+
begin: ({
|
|
591
|
+
node
|
|
592
|
+
}) => {
|
|
572
593
|
doUnlink(toUnlink);
|
|
573
594
|
toUnlink = null;
|
|
574
595
|
if (node.emitStart !== node.emitEnd) {
|
|
575
596
|
return true;
|
|
576
597
|
}
|
|
577
598
|
},
|
|
578
|
-
complete: ({
|
|
599
|
+
complete: ({
|
|
600
|
+
node,
|
|
601
|
+
notGoDeep
|
|
602
|
+
}) => {
|
|
579
603
|
doUnlink(toUnlink);
|
|
580
604
|
toUnlink = null;
|
|
581
605
|
const isSingleRefed = !notGoDeep;
|
|
@@ -600,10 +624,15 @@ function dispose() {
|
|
|
600
624
|
if (upstream.state & State.IsScope) {
|
|
601
625
|
dfs(upstream, {
|
|
602
626
|
isUp: true,
|
|
603
|
-
begin: ({
|
|
627
|
+
begin: ({
|
|
628
|
+
node
|
|
629
|
+
}) => {
|
|
604
630
|
if ((node.state & State.IsScope) === 0 || node.state & ScopeAbort) return true;
|
|
605
631
|
},
|
|
606
|
-
complete: ({
|
|
632
|
+
complete: ({
|
|
633
|
+
node: scope,
|
|
634
|
+
notGoDeep
|
|
635
|
+
}) => {
|
|
607
636
|
const shouldAbort = !notGoDeep;
|
|
608
637
|
if (shouldAbort) {
|
|
609
638
|
releaseScope(scope);
|
|
@@ -619,7 +648,6 @@ function dispose() {
|
|
|
619
648
|
doUnlink(this.emitStart);
|
|
620
649
|
}
|
|
621
650
|
function releaseScope(scope) {
|
|
622
|
-
var _a;
|
|
623
651
|
let outLink = scope.outLink;
|
|
624
652
|
while (outLink) {
|
|
625
653
|
const memoNext = outLink.nextOutLink;
|
|
@@ -627,7 +655,7 @@ function releaseScope(scope) {
|
|
|
627
655
|
outLink = memoNext;
|
|
628
656
|
}
|
|
629
657
|
scope.state |= State.ScopeAbort;
|
|
630
|
-
|
|
658
|
+
scope.clean?.();
|
|
631
659
|
scope.clean = null;
|
|
632
660
|
}
|
|
633
661
|
function clean(cb) {
|
|
@@ -647,82 +675,65 @@ function setPulling(pulling) {
|
|
|
647
675
|
G.PullingSignal = pulling;
|
|
648
676
|
}
|
|
649
677
|
|
|
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;
|
|
678
|
+
const markDeep = root => {
|
|
679
|
+
let node = root,
|
|
680
|
+
i = -1,
|
|
681
|
+
parent;
|
|
682
|
+
const stack = [];
|
|
683
|
+
outer: do {
|
|
684
|
+
let noGoDeep = false;
|
|
685
|
+
const state = node.state,
|
|
686
|
+
emitStart = node.emitStart,
|
|
687
|
+
scheduler = node.scheduler;
|
|
688
|
+
if (node.scope && node.scope.state & State.ScopeAbort ||
|
|
689
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
690
|
+
node.state & ScopeExecuted) {
|
|
691
|
+
noGoDeep = true;
|
|
692
|
+
} else {
|
|
693
|
+
const inPullingArea = state & State.Pulling;
|
|
694
|
+
const isEffect = parent !== void 0;
|
|
695
|
+
const isLeaf = !emitStart || emitStart.downstream === node.scope;
|
|
698
696
|
if (isEffect) {
|
|
699
|
-
node.state |= Unknown;
|
|
697
|
+
node.state |= inPullingArea ? State.PullingUnknown : State.Unknown;
|
|
700
698
|
} else if (!isLeaf) {
|
|
701
699
|
node.state |= State.Dirty;
|
|
702
700
|
}
|
|
703
|
-
if (isLeaf
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
instance.firstEffectItem
|
|
701
|
+
if (isLeaf) {
|
|
702
|
+
noGoDeep = true;
|
|
703
|
+
if (isEffect && !inPullingArea) {
|
|
704
|
+
const instance = _scheduler[scheduler];
|
|
705
|
+
const item = instance.addEffect(node);
|
|
706
|
+
instance.firstEffectItem ??= item;
|
|
707
|
+
instance.lastEffectItem = item;
|
|
709
708
|
}
|
|
710
|
-
instance.lastEffectItem = item;
|
|
711
|
-
updatedSchedulers.add(key);
|
|
712
709
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
710
|
+
}
|
|
711
|
+
if (emitStart && !noGoDeep) {
|
|
712
|
+
stack[++i] = emitStart;
|
|
713
|
+
parent = node;
|
|
714
|
+
node = emitStart.downstream;
|
|
715
|
+
noGoDeep = false;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
while (true) {
|
|
719
|
+
if (i === -1) {
|
|
720
|
+
break outer;
|
|
721
|
+
}
|
|
722
|
+
const backLine = stack[i];
|
|
723
|
+
const nextLine = backLine.nextEmitLine;
|
|
724
|
+
if (nextLine) {
|
|
725
|
+
node = nextLine.downstream;
|
|
726
|
+
stack[i] = nextLine;
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
node = parent;
|
|
730
|
+
if (--i !== -1) {
|
|
731
|
+
parent = stack[i].upstream;
|
|
716
732
|
}
|
|
717
733
|
}
|
|
718
|
-
});
|
|
719
|
-
if (batch.inBatch()) return;
|
|
720
|
-
for (const key in _scheduler) {
|
|
721
|
-
const instance = _scheduler[key];
|
|
722
|
-
instance.endSet();
|
|
723
|
-
}
|
|
734
|
+
} while (true);
|
|
724
735
|
};
|
|
725
|
-
const pullingPostprocess =
|
|
736
|
+
const pullingPostprocess = node => {
|
|
726
737
|
let s = node.state;
|
|
727
738
|
s &= ~State.Pulling;
|
|
728
739
|
if (s & State.PullingUnknown) {
|
|
@@ -730,7 +741,7 @@ const pullingPostprocess = (node) => {
|
|
|
730
741
|
}
|
|
731
742
|
node.state = s;
|
|
732
743
|
};
|
|
733
|
-
|
|
744
|
+
class Signal {
|
|
734
745
|
constructor(nextValue, customPull) {
|
|
735
746
|
this.nextValue = nextValue;
|
|
736
747
|
this.customPull = customPull;
|
|
@@ -750,9 +761,17 @@ const _Signal = class _Signal {
|
|
|
750
761
|
/** 记录当前 effect 中 clean */
|
|
751
762
|
this.clean = null;
|
|
752
763
|
}
|
|
753
|
-
static
|
|
754
|
-
|
|
755
|
-
|
|
764
|
+
static {
|
|
765
|
+
this.Pulling = null;
|
|
766
|
+
}
|
|
767
|
+
static create(nextValue, {
|
|
768
|
+
customPull,
|
|
769
|
+
isScope,
|
|
770
|
+
scope,
|
|
771
|
+
immediate,
|
|
772
|
+
...rest
|
|
773
|
+
}) {
|
|
774
|
+
const s = new Signal(nextValue, customPull);
|
|
756
775
|
s.pull = s.customPull || s.DEFAULT_PULL;
|
|
757
776
|
Object.assign(s, rest);
|
|
758
777
|
if (isScope) {
|
|
@@ -770,10 +789,9 @@ const _Signal = class _Signal {
|
|
|
770
789
|
* 递归拉取负责建立以来链
|
|
771
790
|
*/
|
|
772
791
|
pullRecurse(shouldLink = true) {
|
|
773
|
-
var _a, _b;
|
|
774
792
|
G.PullingRecurseDeep++;
|
|
775
793
|
const downstream = G.PullingSignal;
|
|
776
|
-
this.linkWhenPull(downstream);
|
|
794
|
+
this.linkWhenPull(downstream, shouldLink);
|
|
777
795
|
try {
|
|
778
796
|
if (this.version === G.version) {
|
|
779
797
|
return this.value;
|
|
@@ -781,7 +799,7 @@ const _Signal = class _Signal {
|
|
|
781
799
|
if (this.pull !== this.DEFAULT_PULL) this.recEnd = null;
|
|
782
800
|
this.state |= State.Pulling;
|
|
783
801
|
G.PullingSignal = this;
|
|
784
|
-
|
|
802
|
+
this.clean?.();
|
|
785
803
|
this.clean = null;
|
|
786
804
|
let v = this.pull();
|
|
787
805
|
if (this.state & State.IsScope && typeof v === "function") {
|
|
@@ -798,52 +816,63 @@ const _Signal = class _Signal {
|
|
|
798
816
|
} finally {
|
|
799
817
|
this.pull = this.customPull || this.DEFAULT_PULL;
|
|
800
818
|
pullingPostprocess(this);
|
|
801
|
-
const toDel =
|
|
819
|
+
const toDel = this.recEnd?.nextRecLine;
|
|
802
820
|
unlinkRecWithScope(toDel);
|
|
803
821
|
G.PullingSignal = downstream;
|
|
804
822
|
G.PullingRecurseDeep--;
|
|
805
823
|
}
|
|
806
824
|
}
|
|
807
|
-
linkWhenPull(downstream) {
|
|
825
|
+
linkWhenPull(downstream, shouldLink) {
|
|
808
826
|
const isScope = this.state & State.IsScope;
|
|
809
|
-
if (
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
827
|
+
if (
|
|
828
|
+
// 2. 有下游
|
|
829
|
+
downstream && shouldLink && (
|
|
830
|
+
// 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
|
|
831
|
+
(downstream.state & State.LinkScopeOnly) === 0 || isScope) && (
|
|
832
|
+
/**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
|
|
833
|
+
* 发生在 outEffect(() => scope(() => innerEffect(), null))
|
|
834
|
+
* 虽然通过 scope 让 innerEffect 被管理,
|
|
835
|
+
* 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
|
|
836
|
+
* 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
|
|
837
|
+
*/
|
|
838
|
+
!isScope || !this.emitStart)) {
|
|
818
839
|
Line.link(this, downstream);
|
|
819
840
|
}
|
|
820
841
|
}
|
|
821
842
|
pullDeep() {
|
|
822
843
|
const signal = this;
|
|
823
844
|
if (signal.state & DirtyState) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
845
|
+
let node = signal,
|
|
846
|
+
i = -1,
|
|
847
|
+
parent;
|
|
848
|
+
const stack = [];
|
|
849
|
+
outer: do {
|
|
850
|
+
let noGoDeep = false;
|
|
851
|
+
if (node.state & (State.Pulling | State.Dirty) || (node.state & DirtyState) === 0 || node.isDisabled()) {
|
|
852
|
+
noGoDeep = true;
|
|
853
|
+
} else {
|
|
830
854
|
node.state |= State.Pulling;
|
|
831
|
-
}
|
|
832
|
-
|
|
855
|
+
}
|
|
856
|
+
const recStart = node.recStart;
|
|
857
|
+
if (recStart && !noGoDeep) {
|
|
858
|
+
stack[++i] = recStart;
|
|
859
|
+
parent = node;
|
|
860
|
+
node = recStart.upstream;
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
while (true) {
|
|
833
864
|
const isDirty = node.state & State.Dirty;
|
|
834
|
-
let currentClean =
|
|
835
|
-
if (
|
|
865
|
+
let currentClean = noGoDeep && !isDirty;
|
|
866
|
+
if (noGoDeep && node.state & State.Pulling) {
|
|
836
867
|
currentClean = true;
|
|
837
868
|
}
|
|
838
869
|
let noGoSibling = false;
|
|
839
|
-
const
|
|
840
|
-
const
|
|
870
|
+
const downstream2 = parent;
|
|
871
|
+
const isEmitter = node.pull === node.DEFAULT_PULL;
|
|
841
872
|
if (currentClean) ; else if (isDirty) {
|
|
842
|
-
if (
|
|
873
|
+
if (isEmitter && node.value !== node.nextValue) {
|
|
843
874
|
node.markDownStreamsDirty();
|
|
844
875
|
node.state &= ~State.Dirty;
|
|
845
|
-
node.state &= ~State.Pulling;
|
|
846
|
-
return;
|
|
847
876
|
} else {
|
|
848
877
|
const prevPulling = G.PullingSignal;
|
|
849
878
|
G.PullingSignal = downstream2;
|
|
@@ -859,14 +888,31 @@ const _Signal = class _Signal {
|
|
|
859
888
|
} else if (node.state & State.Unknown) {
|
|
860
889
|
node.state &= ~State.Unknown;
|
|
861
890
|
}
|
|
862
|
-
|
|
891
|
+
if (!isEmitter) {
|
|
892
|
+
node.version = G.version;
|
|
893
|
+
}
|
|
863
894
|
pullingPostprocess(node);
|
|
864
|
-
|
|
895
|
+
noGoDeep = false;
|
|
896
|
+
if (i === -1) {
|
|
897
|
+
break outer;
|
|
898
|
+
}
|
|
899
|
+
const backLine = stack[i];
|
|
900
|
+
const nextLine = backLine.nextRecLine;
|
|
901
|
+
if (!noGoSibling && nextLine) {
|
|
902
|
+
node = nextLine.upstream;
|
|
903
|
+
stack[i] = nextLine;
|
|
904
|
+
break;
|
|
905
|
+
} else {
|
|
906
|
+
node = parent;
|
|
907
|
+
if (--i !== -1) {
|
|
908
|
+
parent = stack[i].downstream;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
865
911
|
}
|
|
866
|
-
});
|
|
912
|
+
} while (true);
|
|
867
913
|
}
|
|
868
914
|
const downstream = G.PullingSignal;
|
|
869
|
-
this.linkWhenPull(downstream);
|
|
915
|
+
this.linkWhenPull(downstream, true);
|
|
870
916
|
return this.value;
|
|
871
917
|
}
|
|
872
918
|
get v() {
|
|
@@ -900,7 +946,18 @@ const _Signal = class _Signal {
|
|
|
900
946
|
this.nextValue = v;
|
|
901
947
|
this.pull = this.DEFAULT_PULL;
|
|
902
948
|
G.version++;
|
|
903
|
-
|
|
949
|
+
if (this.emitStart) {
|
|
950
|
+
markDeep(this);
|
|
951
|
+
if (batchDeep === 0) {
|
|
952
|
+
this.scheduleEffect();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
scheduleEffect() {
|
|
957
|
+
for (const key in _scheduler) {
|
|
958
|
+
const instance = _scheduler[key];
|
|
959
|
+
instance.endSet();
|
|
960
|
+
}
|
|
904
961
|
}
|
|
905
962
|
/** 返回值为 true 表示已处理 */
|
|
906
963
|
runIfDirty() {
|
|
@@ -909,42 +966,32 @@ const _Signal = class _Signal {
|
|
|
909
966
|
isDisabled() {
|
|
910
967
|
return (
|
|
911
968
|
// scope 被取消
|
|
912
|
-
this.scope && this.scope.state & State.ScopeAbort ||
|
|
913
|
-
|
|
969
|
+
this.scope && this.scope.state & State.ScopeAbort ||
|
|
970
|
+
// 是 scope 节点,且处于 ready 状态,不需要重复执行
|
|
971
|
+
this.state & ScopeExecuted
|
|
914
972
|
);
|
|
915
973
|
}
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
974
|
+
}
|
|
975
|
+
let batchDeep = 0;
|
|
976
|
+
function batchStart() {
|
|
977
|
+
batchDeep++;
|
|
978
|
+
}
|
|
979
|
+
function batchEnd() {
|
|
980
|
+
if (--batchDeep) return;
|
|
981
|
+
for (const key in _scheduler) {
|
|
982
|
+
const instance = _scheduler[key];
|
|
983
|
+
instance.endSet();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
919
986
|
|
|
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
987
|
const deepSignal = (target, scope, deep = true) => {
|
|
940
|
-
var _a;
|
|
941
988
|
const isObj = typeof target === "object" && target !== null;
|
|
942
989
|
if (!isObj || target[Keys.Raw]) return target;
|
|
943
990
|
const p = rawToProxy.get(target);
|
|
944
991
|
if (p) return p;
|
|
945
|
-
const cells = /* @__PURE__ */
|
|
992
|
+
const cells = /* @__PURE__ */new Map();
|
|
946
993
|
const targetIsArray = Array.isArray(target);
|
|
947
|
-
const targetIsStore = Boolean(
|
|
994
|
+
const targetIsStore = Boolean(target.constructor?.[IsStore]);
|
|
948
995
|
const meta = {
|
|
949
996
|
deep,
|
|
950
997
|
scope,
|
|
@@ -993,7 +1040,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
993
1040
|
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === "function") {
|
|
994
1041
|
return Reflect.set(obj, prop, value, receiver);
|
|
995
1042
|
}
|
|
996
|
-
|
|
1043
|
+
batchStart();
|
|
997
1044
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
998
1045
|
const cell = cells.get(prop);
|
|
999
1046
|
if (cell) {
|
|
@@ -1004,7 +1051,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
1004
1051
|
} else {
|
|
1005
1052
|
triggerIter(obj, prop, value, receiver);
|
|
1006
1053
|
}
|
|
1007
|
-
|
|
1054
|
+
batchEnd();
|
|
1008
1055
|
return success;
|
|
1009
1056
|
},
|
|
1010
1057
|
// 【核心修改】拦截 delete 操作
|
|
@@ -1033,10 +1080,14 @@ const shareSignal = (from, fromPath, to, toPath) => {
|
|
|
1033
1080
|
const toPaths = toPath.split(".");
|
|
1034
1081
|
const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
|
|
1035
1082
|
runWithPulling(() => {
|
|
1036
|
-
const
|
|
1083
|
+
const _getTargetAndKey = getTargetAndKey(from, formPaths),
|
|
1084
|
+
fromTarget = _getTargetAndKey.target,
|
|
1085
|
+
fromKey = _getTargetAndKey.key;
|
|
1037
1086
|
const val = fromTarget[fromKey];
|
|
1038
1087
|
const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
|
|
1039
|
-
const
|
|
1088
|
+
const _getTargetAndKey2 = getTargetAndKey(to, toPaths),
|
|
1089
|
+
toTarget = _getTargetAndKey2.target,
|
|
1090
|
+
toKey = _getTargetAndKey2.key;
|
|
1040
1091
|
toTarget[Keys.Meta].cells.set(toKey, fromSignal);
|
|
1041
1092
|
toTarget[Keys.Raw][toKey] = val;
|
|
1042
1093
|
}, null);
|
|
@@ -1055,13 +1106,16 @@ function getTargetAndKey(obj, paths) {
|
|
|
1055
1106
|
target = target[key];
|
|
1056
1107
|
}
|
|
1057
1108
|
}
|
|
1058
|
-
return {
|
|
1109
|
+
return {
|
|
1110
|
+
target,
|
|
1111
|
+
key
|
|
1112
|
+
};
|
|
1059
1113
|
}
|
|
1060
1114
|
function isIgnoreKey(ignores, key) {
|
|
1061
1115
|
if (typeof key !== "string") {
|
|
1062
1116
|
return ignores.includes(key);
|
|
1063
1117
|
}
|
|
1064
|
-
return ignores.some(
|
|
1118
|
+
return ignores.some(it => typeof it === "string" && key.startsWith(it));
|
|
1065
1119
|
}
|
|
1066
1120
|
function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
|
|
1067
1121
|
let s = cells.get(prop);
|
|
@@ -1090,18 +1144,18 @@ function triggerIter(obj, prop, value, receiver) {
|
|
|
1090
1144
|
}
|
|
1091
1145
|
}
|
|
1092
1146
|
const arrayMethodReWrites = {};
|
|
1093
|
-
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(
|
|
1094
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1095
|
-
|
|
1147
|
+
["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(key => {
|
|
1148
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1149
|
+
batchStart();
|
|
1096
1150
|
const fn = Array.prototype[key];
|
|
1097
1151
|
const res = runWithPulling(() => fn.call(this, ...args), null);
|
|
1098
1152
|
this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
|
|
1099
|
-
|
|
1153
|
+
batchEnd();
|
|
1100
1154
|
return res;
|
|
1101
1155
|
};
|
|
1102
1156
|
});
|
|
1103
|
-
["includes", "indexOf", "lastIndexOf"].forEach(
|
|
1104
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1157
|
+
["includes", "indexOf", "lastIndexOf"].forEach(key => {
|
|
1158
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1105
1159
|
const fn = Array.prototype[key];
|
|
1106
1160
|
const that = toRaw(this);
|
|
1107
1161
|
let result = fn.call(that, ...args);
|
|
@@ -1121,14 +1175,15 @@ const arrayMethodReWrites = {};
|
|
|
1121
1175
|
return result;
|
|
1122
1176
|
};
|
|
1123
1177
|
});
|
|
1124
|
-
[Symbol.iterator, "values", "entries"].forEach(
|
|
1178
|
+
[Symbol.iterator, "values", "entries"].forEach(key => {
|
|
1125
1179
|
const isEntries = key === "entries";
|
|
1126
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1180
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1127
1181
|
const fn = Array.prototype[key];
|
|
1128
1182
|
const rawArray = toRaw(this);
|
|
1129
1183
|
const iter = fn.call(rawArray, ...args);
|
|
1130
1184
|
const meta = this[Keys.Meta];
|
|
1131
|
-
const
|
|
1185
|
+
const isDeep = meta.deep,
|
|
1186
|
+
scope = meta.scope;
|
|
1132
1187
|
if (isDeep) {
|
|
1133
1188
|
const rawNext = iter.next.bind(iter);
|
|
1134
1189
|
iter.next = () => {
|
|
@@ -1147,9 +1202,10 @@ const arrayMethodReWrites = {};
|
|
|
1147
1202
|
return iter;
|
|
1148
1203
|
};
|
|
1149
1204
|
});
|
|
1150
|
-
arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
1205
|
+
arrayMethodReWrites.filter = function (callback, thisArg) {
|
|
1151
1206
|
const meta = this[Keys.Meta];
|
|
1152
|
-
const
|
|
1207
|
+
const isDeep = meta.deep,
|
|
1208
|
+
scope = meta.scope;
|
|
1153
1209
|
const that = toRaw(this);
|
|
1154
1210
|
const result = [];
|
|
1155
1211
|
let resultIndex = 0;
|
|
@@ -1166,9 +1222,10 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
|
|
|
1166
1222
|
this[Keys.Iterator];
|
|
1167
1223
|
return result;
|
|
1168
1224
|
};
|
|
1169
|
-
arrayMethodReWrites.slice = function(start, end) {
|
|
1225
|
+
arrayMethodReWrites.slice = function (start, end) {
|
|
1170
1226
|
const meta = this[Keys.Meta];
|
|
1171
|
-
const
|
|
1227
|
+
const isDeep = meta.deep,
|
|
1228
|
+
scope = meta.scope;
|
|
1172
1229
|
const that = toRaw(this);
|
|
1173
1230
|
const len = that.length;
|
|
1174
1231
|
let k = start || 0;
|
|
@@ -1193,9 +1250,10 @@ arrayMethodReWrites.slice = function(start, end) {
|
|
|
1193
1250
|
this[Keys.Iterator];
|
|
1194
1251
|
return result;
|
|
1195
1252
|
};
|
|
1196
|
-
arrayMethodReWrites.toReversed = function() {
|
|
1253
|
+
arrayMethodReWrites.toReversed = function () {
|
|
1197
1254
|
const meta = this[Keys.Meta];
|
|
1198
|
-
const
|
|
1255
|
+
const isDeep = meta.deep,
|
|
1256
|
+
scope = meta.scope;
|
|
1199
1257
|
const that = toRaw(this);
|
|
1200
1258
|
const len = that.length;
|
|
1201
1259
|
const result = new Array(len);
|
|
@@ -1207,9 +1265,10 @@ arrayMethodReWrites.toReversed = function() {
|
|
|
1207
1265
|
this[Keys.Iterator];
|
|
1208
1266
|
return result;
|
|
1209
1267
|
};
|
|
1210
|
-
arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
1268
|
+
arrayMethodReWrites.toSpliced = function (start, deleteCount, ...items) {
|
|
1211
1269
|
const meta = this[Keys.Meta];
|
|
1212
|
-
const
|
|
1270
|
+
const isDeep = meta.deep,
|
|
1271
|
+
scope = meta.scope;
|
|
1213
1272
|
const that = toRaw(this);
|
|
1214
1273
|
const len = that.length;
|
|
1215
1274
|
let relativeStart = start >> 0;
|
|
@@ -1240,9 +1299,10 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
|
|
|
1240
1299
|
this[Keys.Iterator];
|
|
1241
1300
|
return result;
|
|
1242
1301
|
};
|
|
1243
|
-
arrayMethodReWrites.with = function(index, value) {
|
|
1302
|
+
arrayMethodReWrites.with = function (index, value) {
|
|
1244
1303
|
const meta = this[Keys.Meta];
|
|
1245
|
-
const
|
|
1304
|
+
const isDeep = meta.deep,
|
|
1305
|
+
scope = meta.scope;
|
|
1246
1306
|
const that = toRaw(this);
|
|
1247
1307
|
const len = that.length;
|
|
1248
1308
|
let relativeIndex = Number(index) || 0;
|
|
@@ -1261,9 +1321,10 @@ arrayMethodReWrites.with = function(index, value) {
|
|
|
1261
1321
|
this[Keys.Iterator];
|
|
1262
1322
|
return result;
|
|
1263
1323
|
};
|
|
1264
|
-
arrayMethodReWrites.concat = function(...items) {
|
|
1324
|
+
arrayMethodReWrites.concat = function (...items) {
|
|
1265
1325
|
const meta = this[Keys.Meta];
|
|
1266
|
-
const
|
|
1326
|
+
const isDeep = meta.deep,
|
|
1327
|
+
scope = meta.scope;
|
|
1267
1328
|
const that = toRaw(this);
|
|
1268
1329
|
const selfLen = that.length;
|
|
1269
1330
|
let totalLength = selfLen;
|
|
@@ -1303,49 +1364,50 @@ const GetMethodConf = {
|
|
|
1303
1364
|
wrapReturn: false,
|
|
1304
1365
|
wrapArgs: 1
|
|
1305
1366
|
};
|
|
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) {
|
|
1367
|
+
[{
|
|
1368
|
+
key: "every",
|
|
1369
|
+
...GetMethodConf
|
|
1370
|
+
}, {
|
|
1371
|
+
key: "find",
|
|
1372
|
+
wrapReturn: true,
|
|
1373
|
+
...GetMethodConf
|
|
1374
|
+
}, {
|
|
1375
|
+
key: "findLast",
|
|
1376
|
+
...GetMethodConf,
|
|
1377
|
+
wrapReturn: true
|
|
1378
|
+
}, {
|
|
1379
|
+
key: "findIndex",
|
|
1380
|
+
...GetMethodConf
|
|
1381
|
+
}, {
|
|
1382
|
+
key: "findLastIndex",
|
|
1383
|
+
...GetMethodConf
|
|
1384
|
+
}, {
|
|
1385
|
+
key: "forEach",
|
|
1386
|
+
...GetMethodConf
|
|
1387
|
+
}, {
|
|
1388
|
+
key: "map",
|
|
1389
|
+
...GetMethodConf
|
|
1390
|
+
}, {
|
|
1391
|
+
key: "some",
|
|
1392
|
+
...GetMethodConf
|
|
1393
|
+
}, {
|
|
1394
|
+
key: "reduce",
|
|
1395
|
+
...GetMethodConf,
|
|
1396
|
+
wrapArgs: 2
|
|
1397
|
+
}, {
|
|
1398
|
+
key: "reduceRight",
|
|
1399
|
+
...GetMethodConf,
|
|
1400
|
+
wrapArgs: 2
|
|
1401
|
+
}].forEach(({
|
|
1402
|
+
key,
|
|
1403
|
+
wrapReturn,
|
|
1404
|
+
wrapArgs
|
|
1405
|
+
}) => {
|
|
1406
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1346
1407
|
const meta = this[Keys.Meta];
|
|
1347
1408
|
const fn = Array.prototype[key];
|
|
1348
|
-
const
|
|
1409
|
+
const isDeep = meta.deep,
|
|
1410
|
+
scope = meta.scope;
|
|
1349
1411
|
const that = toRaw(this);
|
|
1350
1412
|
warpCallbackArgs(isDeep, args, scope, wrapArgs);
|
|
1351
1413
|
let result = fn.call(that, ...args);
|
|
@@ -1356,18 +1418,19 @@ const GetMethodConf = {
|
|
|
1356
1418
|
return result;
|
|
1357
1419
|
};
|
|
1358
1420
|
});
|
|
1359
|
-
arrayMethodReWrites.toSorted = function(...args) {
|
|
1421
|
+
arrayMethodReWrites.toSorted = function (...args) {
|
|
1360
1422
|
const fn = Array.prototype["toSorted"];
|
|
1361
1423
|
const meta = this[Keys.Meta];
|
|
1362
|
-
const
|
|
1424
|
+
const isDeep = meta.deep,
|
|
1425
|
+
scope = meta.scope;
|
|
1363
1426
|
const that = toRaw(this);
|
|
1364
1427
|
warpCallbackArgs(isDeep, args, scope, 3);
|
|
1365
1428
|
let result = fn.call(that, ...args);
|
|
1366
1429
|
this[Keys.Iterator];
|
|
1367
|
-
return isDeep ? result.map(
|
|
1430
|
+
return isDeep ? result.map(it => deepSignal(it, scope)) : result;
|
|
1368
1431
|
};
|
|
1369
|
-
["join", "toString", "toLocaleString"].forEach(
|
|
1370
|
-
arrayMethodReWrites[key] = function(...args) {
|
|
1432
|
+
["join", "toString", "toLocaleString"].forEach(key => {
|
|
1433
|
+
arrayMethodReWrites[key] = function (...args) {
|
|
1371
1434
|
const fn = Array.prototype[key];
|
|
1372
1435
|
const that = toRaw(this);
|
|
1373
1436
|
const result = fn.call(that, ...args);
|
|
@@ -1377,7 +1440,7 @@ arrayMethodReWrites.toSorted = function(...args) {
|
|
|
1377
1440
|
});
|
|
1378
1441
|
function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
|
|
1379
1442
|
const callback = args[0];
|
|
1380
|
-
const wrapCb = function(...cbArgs) {
|
|
1443
|
+
const wrapCb = function (...cbArgs) {
|
|
1381
1444
|
if (isDeep) {
|
|
1382
1445
|
if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
|
|
1383
1446
|
if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
|
|
@@ -1396,6 +1459,15 @@ const _Store = class _Store {
|
|
|
1396
1459
|
_Store.Current = proxy;
|
|
1397
1460
|
return proxy;
|
|
1398
1461
|
}
|
|
1462
|
+
static {
|
|
1463
|
+
this[_b] = true;
|
|
1464
|
+
}
|
|
1465
|
+
static {
|
|
1466
|
+
this[_a] = ["ui", "raw"];
|
|
1467
|
+
}
|
|
1468
|
+
static {
|
|
1469
|
+
this.Current = null;
|
|
1470
|
+
}
|
|
1399
1471
|
static new(keyMap = {}, staticMap = {}) {
|
|
1400
1472
|
const parentStore = _Store.Current;
|
|
1401
1473
|
const child = new this();
|
|
@@ -1424,27 +1496,8 @@ const _Store = class _Store {
|
|
|
1424
1496
|
this.parent = null;
|
|
1425
1497
|
}
|
|
1426
1498
|
};
|
|
1427
|
-
_Store[_b] = true;
|
|
1428
|
-
_Store[_a] = ["ui", "raw"];
|
|
1429
|
-
_Store.Current = null;
|
|
1430
1499
|
let Store = _Store;
|
|
1431
1500
|
|
|
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
1501
|
const DefaultCustomSignalOpt = {
|
|
1449
1502
|
/** 三种模式
|
|
1450
1503
|
* 1. auto: 根据值类型自动判断 默认
|
|
@@ -1458,7 +1511,10 @@ const DefaultCustomSignalOpt = {
|
|
|
1458
1511
|
({
|
|
1459
1512
|
scheduler: Scheduler.Sync});
|
|
1460
1513
|
const $ = (init, opt = {}) => {
|
|
1461
|
-
opt =
|
|
1514
|
+
opt = {
|
|
1515
|
+
...DefaultCustomSignalOpt,
|
|
1516
|
+
...opt
|
|
1517
|
+
};
|
|
1462
1518
|
let intiValue, customPull;
|
|
1463
1519
|
if (typeof init === "function") {
|
|
1464
1520
|
intiValue = null;
|
|
@@ -1476,15 +1532,15 @@ const $ = (init, opt = {}) => {
|
|
|
1476
1532
|
return s;
|
|
1477
1533
|
};
|
|
1478
1534
|
const effect = (customPull, depOrOpt, opt) => {
|
|
1479
|
-
var _a;
|
|
1480
1535
|
const hasDep = Array.isArray(depOrOpt);
|
|
1481
1536
|
opt = hasDep ? opt || {} : depOrOpt || {};
|
|
1482
1537
|
if (!hasDep) {
|
|
1483
|
-
const s2 = Signal.create(null,
|
|
1538
|
+
const s2 = Signal.create(null, {
|
|
1484
1539
|
customPull,
|
|
1485
1540
|
scheduler: Scheduler.Sync,
|
|
1486
|
-
isScope: true
|
|
1487
|
-
|
|
1541
|
+
isScope: true,
|
|
1542
|
+
...opt
|
|
1543
|
+
});
|
|
1488
1544
|
s2.v;
|
|
1489
1545
|
const bound2 = dispose.bind(s2);
|
|
1490
1546
|
bound2.ins = s2;
|
|
@@ -1492,9 +1548,14 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1492
1548
|
}
|
|
1493
1549
|
let mounted = false;
|
|
1494
1550
|
const deps = depOrOpt;
|
|
1495
|
-
const immediate = deps.length === 0 ? true :
|
|
1496
|
-
const vs = Array.from({
|
|
1497
|
-
|
|
1551
|
+
const immediate = deps.length === 0 ? true : opt.immediate ?? true;
|
|
1552
|
+
const vs = Array.from({
|
|
1553
|
+
length: deps.length
|
|
1554
|
+
}, () => ({
|
|
1555
|
+
old: null,
|
|
1556
|
+
val: null
|
|
1557
|
+
}));
|
|
1558
|
+
const s = Signal.create(null, {
|
|
1498
1559
|
customPull() {
|
|
1499
1560
|
for (let i = 0; i < deps.length; i++) {
|
|
1500
1561
|
const value = deps[i].v;
|
|
@@ -1509,8 +1570,9 @@ const effect = (customPull, depOrOpt, opt) => {
|
|
|
1509
1570
|
mounted = true;
|
|
1510
1571
|
},
|
|
1511
1572
|
scheduler: Scheduler.Sync,
|
|
1512
|
-
isScope: true
|
|
1513
|
-
|
|
1573
|
+
isScope: true,
|
|
1574
|
+
...opt
|
|
1575
|
+
});
|
|
1514
1576
|
s.v;
|
|
1515
1577
|
const bound = dispose.bind(s);
|
|
1516
1578
|
bound.ins = s;
|
|
@@ -1536,17 +1598,20 @@ const scope = (...args) => {
|
|
|
1536
1598
|
bound.ins = s;
|
|
1537
1599
|
return bound;
|
|
1538
1600
|
};
|
|
1539
|
-
const customEffect =
|
|
1540
|
-
return (
|
|
1541
|
-
return effect(init,
|
|
1542
|
-
|
|
1601
|
+
const customEffect = opt => {
|
|
1602
|
+
return (init, innerOpt = {}) => {
|
|
1603
|
+
return effect(init, {
|
|
1604
|
+
...opt,
|
|
1605
|
+
...innerOpt
|
|
1606
|
+
});
|
|
1607
|
+
};
|
|
1543
1608
|
};
|
|
1544
|
-
const isSignal =
|
|
1609
|
+
const isSignal = value => {
|
|
1545
1610
|
return value instanceof Signal;
|
|
1546
1611
|
};
|
|
1547
|
-
const isScope =
|
|
1612
|
+
const isScope = value => {
|
|
1548
1613
|
return value instanceof Signal;
|
|
1549
1614
|
};
|
|
1550
1615
|
|
|
1551
|
-
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue,
|
|
1616
|
+
export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batchEnd, batchStart, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal, toRaw };
|
|
1552
1617
|
//# sourceMappingURL=aoye.esm.js.map
|