aoye 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aoye.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var bobeShared = require('bobe-shared');
4
4
 
5
- const rawToProxy = /* @__PURE__ */ new WeakMap();
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__ */ ((State2) => {
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) => [arr[i], arr[j]] = [arr[j], arr[i]];
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((it) => this._add(it));
95
+ items.forEach(it => this._add(it));
91
96
  }
92
97
  // 去除头元素并返回
93
98
  poll() {
94
- const { arr } = this;
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 { arr } = this;
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((it) => {
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({ callbackAble, aIsUrgent }) {
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 { taskQueue, isScheduling } = this;
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 { taskQueue } = this;
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 = __spreadValues$3(__spreadValues$3({}, DefaultTaskControlReturn), 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__ */ ((Keys2) => {
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__ */ Symbol("__AOYE_IS_STORE"), StoreIgnoreKeys = /* @__PURE__ */ Symbol("__AOYE_IGNORE_KEYS");
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 = (fn) => {
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 = (cb) => {
221
+ const micro = cb => {
225
222
  p.then(cb);
226
223
  };
227
- const toRaw = (a) => {
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
- (_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
256
+ this.onOneSetEffectsAdded?.(subQueue, this.effectQueue);
249
257
  }
250
258
  addEffect(effect) {
251
- var _a;
252
259
  const item = this.effectQueue.push(effect);
253
- (_a = this.onEffectAdded) == null ? void 0 : _a.call(this, effect, item, this.effectQueue);
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({ callbackAble: micro, aIsUrgent: (a, b) => a.time < b.time });
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({ callbackAble: macro, aIsUrgent: (a, b) => a.time < b.time });
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({ callbackAble: macro, aIsUrgent: (a, b) => a.time < b.time });
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,74 +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
- const DefaultDFSOpt = {
347
- isUp: false,
348
- begin: null,
349
- complete: null,
350
- breakStack: [],
351
- breakLine: null,
352
- breakNode: null
353
- };
354
- function dfs(root, opt = {}) {
355
- const { isUp, begin, complete, breakStack: lineStack, breakLine } = __spreadValues$2(__spreadValues$2({}, DefaultDFSOpt), opt);
356
- let node = opt.breakNode || root;
357
- let line = breakLine;
358
- const listKey = isUp ? "recStart" : "emitStart";
359
- const nodeKey = isUp ? "upstream" : "downstream";
360
- const nextLineKey = isUp ? "nextRecLine" : "nextEmitLine";
361
- const reverseNodeKey = isUp ? "downstream" : "upstream";
362
- while (1) {
363
- let notGoDeep = begin == null ? void 0 : begin({
364
- node,
365
- lineFromUp: line,
366
- walkedLine: lineStack
367
- });
368
- lineStack.push(line);
369
- line = node[listKey];
370
- if (line && !notGoDeep) {
371
- const firstChild = line[nodeKey];
372
- node = firstChild;
373
- continue;
374
- }
375
- while (1) {
376
- const noGoSibling = complete == null ? void 0 : complete({
377
- node,
378
- lineToDeep: line,
379
- walkedLine: lineStack,
380
- notGoDeep
381
- });
382
- line = lineStack.pop();
383
- if (node === root) {
384
- return;
385
- }
386
- notGoDeep = false;
387
- const nextLine = line[nextLineKey];
388
- if (!noGoSibling && nextLine) {
389
- line = nextLine;
390
- node = nextLine[nodeKey];
391
- break;
392
- }
393
- node = line[reverseNodeKey];
394
- }
395
- }
396
- }
397
-
398
342
  class Line {
399
343
  constructor() {
400
344
  /** 上游顶点 */
@@ -414,9 +358,17 @@ class Line {
414
358
  this.nextOutLink = null;
415
359
  }
416
360
  static link(v1, v2) {
417
- let { emitEnd } = v1, { recEnd, recStart } = v2, noRecEnd = !recEnd, head = { nextRecLine: recStart }, line;
361
+ let emitEnd = v1.emitEnd,
362
+ recEnd = v2.recEnd,
363
+ recStart = v2.recStart,
364
+ noRecEnd = !recEnd,
365
+ head = {
366
+ nextRecLine: recStart
367
+ },
368
+ line;
418
369
  recEnd = recEnd || head;
419
- const { nextRecLine } = recEnd || {};
370
+ const _ref = recEnd || {},
371
+ nextRecLine = _ref.nextRecLine;
420
372
  if (!nextRecLine) {
421
373
  line = new Line();
422
374
  Line.emit_line(v1, line);
@@ -447,7 +399,14 @@ class Line {
447
399
  }
448
400
  }
449
401
  static unlink(line) {
450
- let { prevEmitLine, nextEmitLine, prevRecLine, nextRecLine, upstream, downstream, nextOutLink, prevOutLink } = line;
402
+ let prevEmitLine = line.prevEmitLine,
403
+ nextEmitLine = line.nextEmitLine,
404
+ prevRecLine = line.prevRecLine,
405
+ nextRecLine = line.nextRecLine,
406
+ upstream = line.upstream,
407
+ downstream = line.downstream,
408
+ nextOutLink = line.nextOutLink,
409
+ prevOutLink = line.prevOutLink;
451
410
  line.prevEmitLine = null;
452
411
  line.nextEmitLine = null;
453
412
  line.prevRecLine = null;
@@ -568,24 +527,46 @@ function unlinkSingleLine(line) {
568
527
  }
569
528
  function unlinkSingleRefedNode(delRoot) {
570
529
  let toUnlink;
571
- dfs(delRoot, {
572
- isUp: true,
573
- begin: ({ node }) => {
574
- doUnlink(toUnlink);
575
- toUnlink = null;
576
- if (node.emitStart !== node.emitEnd) {
577
- return true;
578
- }
579
- },
580
- complete: ({ node, notGoDeep }) => {
530
+ let node = delRoot,
531
+ i = -1,
532
+ parent;
533
+ const stack = [];
534
+ outer: do {
535
+ let noGoDeep = false;
536
+ doUnlink(toUnlink);
537
+ toUnlink = null;
538
+ noGoDeep = node.emitStart !== node.emitEnd;
539
+ const recStart = node.recStart;
540
+ if (recStart && !noGoDeep) {
541
+ stack[++i] = recStart;
542
+ parent = node;
543
+ node = recStart.upstream;
544
+ continue;
545
+ }
546
+ while (true) {
581
547
  doUnlink(toUnlink);
582
548
  toUnlink = null;
583
- const isSingleRefed = !notGoDeep;
584
- if (isSingleRefed) {
549
+ if (!noGoDeep) {
585
550
  toUnlink = node.emitStart;
586
551
  }
552
+ noGoDeep = false;
553
+ if (i === -1) {
554
+ break outer;
555
+ }
556
+ const backLine = stack[i];
557
+ const nextLine = backLine.nextRecLine;
558
+ if (nextLine) {
559
+ node = nextLine.upstream;
560
+ stack[i] = nextLine;
561
+ break;
562
+ } else {
563
+ node = parent;
564
+ if (--i !== -1) {
565
+ parent = stack[i].downstream;
566
+ }
567
+ }
587
568
  }
588
- });
569
+ } while (true);
589
570
  doUnlink(toUnlink);
590
571
  }
591
572
  function doUnlink(line) {
@@ -600,18 +581,41 @@ function dispose() {
600
581
  const memoNext = toDel.nextRecLine;
601
582
  const upstream = toDel.upstream;
602
583
  if (upstream.state & State.IsScope) {
603
- dfs(upstream, {
604
- isUp: true,
605
- begin: ({ node }) => {
606
- if ((node.state & State.IsScope) === 0 || node.state & ScopeAbort) return true;
607
- },
608
- complete: ({ node: scope, notGoDeep }) => {
609
- const shouldAbort = !notGoDeep;
610
- if (shouldAbort) {
611
- releaseScope(scope);
584
+ let node = upstream,
585
+ i = -1,
586
+ parent;
587
+ const stack = [];
588
+ outer: do {
589
+ let noGoDeep = (node.state & State.IsScope) === 0 || node.state & ScopeAbort;
590
+ const recStart = node.recStart;
591
+ if (recStart && !noGoDeep) {
592
+ stack[++i] = recStart;
593
+ parent = node;
594
+ node = recStart.upstream;
595
+ continue;
596
+ }
597
+ while (true) {
598
+ if (!noGoDeep) {
599
+ releaseScope(node);
600
+ }
601
+ noGoDeep = false;
602
+ if (i === -1) {
603
+ break outer;
604
+ }
605
+ const backLine = stack[i];
606
+ const nextLine = backLine.nextRecLine;
607
+ if (nextLine) {
608
+ node = nextLine.upstream;
609
+ stack[i] = nextLine;
610
+ break;
611
+ } else {
612
+ node = parent;
613
+ if (--i !== -1) {
614
+ parent = stack[i].downstream;
615
+ }
612
616
  }
613
617
  }
614
- });
618
+ } while (true);
615
619
  } else {
616
620
  unlinkSingleLine(toDel);
617
621
  }
@@ -621,7 +625,6 @@ function dispose() {
621
625
  doUnlink(this.emitStart);
622
626
  }
623
627
  function releaseScope(scope) {
624
- var _a;
625
628
  let outLink = scope.outLink;
626
629
  while (outLink) {
627
630
  const memoNext = outLink.nextOutLink;
@@ -629,7 +632,7 @@ function releaseScope(scope) {
629
632
  outLink = memoNext;
630
633
  }
631
634
  scope.state |= State.ScopeAbort;
632
- (_a = scope.clean) == null ? void 0 : _a.call(scope);
635
+ scope.clean?.();
633
636
  scope.clean = null;
634
637
  }
635
638
  function clean(cb) {
@@ -649,82 +652,65 @@ function setPulling(pulling) {
649
652
  G.PullingSignal = pulling;
650
653
  }
651
654
 
652
- class Batch {
653
- constructor() {
654
- this.deep = 0;
655
- }
656
- start() {
657
- this.deep++;
658
- }
659
- end() {
660
- this.deep--;
661
- if (this.deep !== 0) return;
662
- for (const key in _scheduler) {
663
- const instance = _scheduler[key];
664
- instance.endSet();
665
- }
666
- }
667
- inBatch() {
668
- return this.deep > 0;
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;
655
+ const markDeep = root => {
656
+ let node = root,
657
+ i = -1,
658
+ parent;
659
+ const stack = [];
660
+ outer: do {
661
+ let noGoDeep = false;
662
+ const state = node.state,
663
+ emitStart = node.emitStart,
664
+ scheduler = node.scheduler;
665
+ if (node.scope && node.scope.state & State.ScopeAbort ||
666
+ // scope 节点,且处于 ready 状态,不需要重复执行
667
+ node.state & ScopeExecuted) {
668
+ noGoDeep = true;
669
+ } else {
670
+ const inPullingArea = state & State.Pulling;
671
+ const isEffect = parent !== void 0;
672
+ const isLeaf = !emitStart || emitStart.downstream === node.scope;
700
673
  if (isEffect) {
701
- node.state |= Unknown;
674
+ node.state |= inPullingArea ? State.PullingUnknown : State.Unknown;
702
675
  } else if (!isLeaf) {
703
676
  node.state |= State.Dirty;
704
677
  }
705
- if (isLeaf && isEffect && !inPullingArea) {
706
- const key = node.scheduler;
707
- const instance = _scheduler[key];
708
- const item = instance.addEffect(node);
709
- if (!instance.firstEffectItem) {
710
- instance.firstEffectItem = item;
678
+ if (isLeaf) {
679
+ noGoDeep = true;
680
+ if (isEffect && !inPullingArea) {
681
+ const instance = _scheduler[scheduler];
682
+ const item = instance.addEffect(node);
683
+ instance.firstEffectItem ??= item;
684
+ instance.lastEffectItem = item;
711
685
  }
712
- instance.lastEffectItem = item;
713
- updatedSchedulers.add(key);
714
686
  }
715
- level++;
716
- if (isLeaf) {
717
- return true;
687
+ }
688
+ if (emitStart && !noGoDeep) {
689
+ stack[++i] = emitStart;
690
+ parent = node;
691
+ node = emitStart.downstream;
692
+ noGoDeep = false;
693
+ continue;
694
+ }
695
+ while (true) {
696
+ if (i === -1) {
697
+ break outer;
698
+ }
699
+ const backLine = stack[i];
700
+ const nextLine = backLine.nextEmitLine;
701
+ if (nextLine) {
702
+ node = nextLine.downstream;
703
+ stack[i] = nextLine;
704
+ break;
705
+ }
706
+ node = parent;
707
+ if (--i !== -1) {
708
+ parent = stack[i].upstream;
718
709
  }
719
710
  }
720
- });
721
- if (batch.inBatch()) return;
722
- for (const key in _scheduler) {
723
- const instance = _scheduler[key];
724
- instance.endSet();
725
- }
711
+ } while (true);
726
712
  };
727
- const pullingPostprocess = (node) => {
713
+ const pullingPostprocess = node => {
728
714
  let s = node.state;
729
715
  s &= ~State.Pulling;
730
716
  if (s & State.PullingUnknown) {
@@ -732,7 +718,7 @@ const pullingPostprocess = (node) => {
732
718
  }
733
719
  node.state = s;
734
720
  };
735
- const _Signal = class _Signal {
721
+ class Signal {
736
722
  constructor(nextValue, customPull) {
737
723
  this.nextValue = nextValue;
738
724
  this.customPull = customPull;
@@ -752,9 +738,17 @@ const _Signal = class _Signal {
752
738
  /** 记录当前 effect 中 clean */
753
739
  this.clean = null;
754
740
  }
755
- static create(nextValue, _a) {
756
- var _b = _a, { customPull, isScope, scope, immediate } = _b, rest = __objRest(_b, ["customPull", "isScope", "scope", "immediate"]);
757
- const s = new _Signal(nextValue, customPull);
741
+ static {
742
+ this.Pulling = null;
743
+ }
744
+ static create(nextValue, {
745
+ customPull,
746
+ isScope,
747
+ scope,
748
+ immediate,
749
+ ...rest
750
+ }) {
751
+ const s = new Signal(nextValue, customPull);
758
752
  s.pull = s.customPull || s.DEFAULT_PULL;
759
753
  Object.assign(s, rest);
760
754
  if (isScope) {
@@ -772,10 +766,9 @@ const _Signal = class _Signal {
772
766
  * 递归拉取负责建立以来链
773
767
  */
774
768
  pullRecurse(shouldLink = true) {
775
- var _a, _b;
776
769
  G.PullingRecurseDeep++;
777
770
  const downstream = G.PullingSignal;
778
- this.linkWhenPull(downstream);
771
+ this.linkWhenPull(downstream, shouldLink);
779
772
  try {
780
773
  if (this.version === G.version) {
781
774
  return this.value;
@@ -783,7 +776,7 @@ const _Signal = class _Signal {
783
776
  if (this.pull !== this.DEFAULT_PULL) this.recEnd = null;
784
777
  this.state |= State.Pulling;
785
778
  G.PullingSignal = this;
786
- (_a = this.clean) == null ? void 0 : _a.call(this);
779
+ this.clean?.();
787
780
  this.clean = null;
788
781
  let v = this.pull();
789
782
  if (this.state & State.IsScope && typeof v === "function") {
@@ -800,52 +793,63 @@ const _Signal = class _Signal {
800
793
  } finally {
801
794
  this.pull = this.customPull || this.DEFAULT_PULL;
802
795
  pullingPostprocess(this);
803
- const toDel = (_b = this.recEnd) == null ? void 0 : _b.nextRecLine;
796
+ const toDel = this.recEnd?.nextRecLine;
804
797
  unlinkRecWithScope(toDel);
805
798
  G.PullingSignal = downstream;
806
799
  G.PullingRecurseDeep--;
807
800
  }
808
801
  }
809
- linkWhenPull(downstream) {
802
+ linkWhenPull(downstream, shouldLink) {
810
803
  const isScope = this.state & State.IsScope;
811
- if (this !== downstream && // 2. 有下游
812
- downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
813
- ((downstream.state & State.LinkScopeOnly) === 0 || isScope) && /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
814
- * 发生在 outEffect(() => scope(() => innerEffect(), null))
815
- * 虽然通过 scope innerEffect 被管理,
816
- * 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
817
- * outEffect 后续重新触发, 则导致 innerEffect 被销毁
818
- */
819
- (!isScope || !this.emitStart)) {
804
+ if (
805
+ // 2. 有下游
806
+ downstream && shouldLink && (
807
+ // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
808
+ (downstream.state & State.LinkScopeOnly) === 0 || isScope) && (
809
+ /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
810
+ * 发生在 outEffect(() => scope(() => innerEffect(), null))
811
+ * 虽然通过 scope 让 innerEffect 被管理,
812
+ * 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
813
+ * 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
814
+ */
815
+ !isScope || !this.emitStart)) {
820
816
  Line.link(this, downstream);
821
817
  }
822
818
  }
823
819
  pullDeep() {
824
820
  const signal = this;
825
821
  if (signal.state & DirtyState) {
826
- dfs(signal, {
827
- isUp: true,
828
- begin: ({ node }) => {
829
- if (node.state & (State.Pulling | State.Dirty) || (node.state & DirtyState) === 0 || node.isDisabled()) {
830
- return true;
831
- }
822
+ let node = signal,
823
+ i = -1,
824
+ parent;
825
+ const stack = [];
826
+ outer: do {
827
+ let noGoDeep = false;
828
+ if (node.state & (State.Pulling | State.Dirty) || (node.state & DirtyState) === 0 || node.isDisabled()) {
829
+ noGoDeep = true;
830
+ } else {
832
831
  node.state |= State.Pulling;
833
- },
834
- complete: ({ node, notGoDeep: cleanOrDirty, walkedLine }) => {
832
+ }
833
+ const recStart = node.recStart;
834
+ if (recStart && !noGoDeep) {
835
+ stack[++i] = recStart;
836
+ parent = node;
837
+ node = recStart.upstream;
838
+ continue;
839
+ }
840
+ while (true) {
835
841
  const isDirty = node.state & State.Dirty;
836
- let currentClean = cleanOrDirty && !isDirty;
837
- if (cleanOrDirty && node.state & State.Pulling) {
842
+ let currentClean = noGoDeep && !isDirty;
843
+ if (noGoDeep && node.state & State.Pulling) {
838
844
  currentClean = true;
839
845
  }
840
846
  let noGoSibling = false;
841
- const last = walkedLine[walkedLine.length - 1];
842
- const downstream2 = last == null ? void 0 : last.downstream;
847
+ const downstream2 = parent;
848
+ const isEmitter = node.pull === node.DEFAULT_PULL;
843
849
  if (currentClean) ; else if (isDirty) {
844
- if (node.pull === node.DEFAULT_PULL && node.value !== node.nextValue) {
850
+ if (isEmitter && node.value !== node.nextValue) {
845
851
  node.markDownStreamsDirty();
846
852
  node.state &= ~State.Dirty;
847
- node.state &= ~State.Pulling;
848
- return;
849
853
  } else {
850
854
  const prevPulling = G.PullingSignal;
851
855
  G.PullingSignal = downstream2;
@@ -861,14 +865,31 @@ const _Signal = class _Signal {
861
865
  } else if (node.state & State.Unknown) {
862
866
  node.state &= ~State.Unknown;
863
867
  }
864
- node.version = G.version;
868
+ if (!isEmitter) {
869
+ node.version = G.version;
870
+ }
865
871
  pullingPostprocess(node);
866
- return noGoSibling;
872
+ noGoDeep = false;
873
+ if (i === -1) {
874
+ break outer;
875
+ }
876
+ const backLine = stack[i];
877
+ const nextLine = backLine.nextRecLine;
878
+ if (!noGoSibling && nextLine) {
879
+ node = nextLine.upstream;
880
+ stack[i] = nextLine;
881
+ break;
882
+ } else {
883
+ node = parent;
884
+ if (--i !== -1) {
885
+ parent = stack[i].downstream;
886
+ }
887
+ }
867
888
  }
868
- });
889
+ } while (true);
869
890
  }
870
891
  const downstream = G.PullingSignal;
871
- this.linkWhenPull(downstream);
892
+ this.linkWhenPull(downstream, true);
872
893
  return this.value;
873
894
  }
874
895
  get v() {
@@ -902,7 +923,18 @@ const _Signal = class _Signal {
902
923
  this.nextValue = v;
903
924
  this.pull = this.DEFAULT_PULL;
904
925
  G.version++;
905
- markDeep(this);
926
+ if (this.emitStart) {
927
+ markDeep(this);
928
+ if (batchDeep === 0) {
929
+ this.scheduleEffect();
930
+ }
931
+ }
932
+ }
933
+ scheduleEffect() {
934
+ for (const key in _scheduler) {
935
+ const instance = _scheduler[key];
936
+ instance.endSet();
937
+ }
906
938
  }
907
939
  /** 返回值为 true 表示已处理 */
908
940
  runIfDirty() {
@@ -911,42 +943,32 @@ const _Signal = class _Signal {
911
943
  isDisabled() {
912
944
  return (
913
945
  // scope 被取消
914
- this.scope && this.scope.state & State.ScopeAbort || // 是 scope 节点,且处于 ready 状态,不需要重复执行
915
- this.state & State.IsScope && this.state & ScopeExecuted
946
+ this.scope && this.scope.state & State.ScopeAbort ||
947
+ // scope 节点,且处于 ready 状态,不需要重复执行
948
+ this.state & ScopeExecuted
916
949
  );
917
950
  }
918
- };
919
- _Signal.Pulling = null;
920
- let Signal = _Signal;
951
+ }
952
+ let batchDeep = 0;
953
+ function batchStart() {
954
+ batchDeep++;
955
+ }
956
+ function batchEnd() {
957
+ if (--batchDeep) return;
958
+ for (const key in _scheduler) {
959
+ const instance = _scheduler[key];
960
+ instance.endSet();
961
+ }
962
+ }
921
963
 
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
964
  const deepSignal = (target, scope, deep = true) => {
942
- var _a;
943
965
  const isObj = typeof target === "object" && target !== null;
944
966
  if (!isObj || target[Keys.Raw]) return target;
945
967
  const p = rawToProxy.get(target);
946
968
  if (p) return p;
947
- const cells = /* @__PURE__ */ new Map();
969
+ const cells = /* @__PURE__ */new Map();
948
970
  const targetIsArray = Array.isArray(target);
949
- const targetIsStore = Boolean((_a = target.constructor) == null ? void 0 : _a[IsStore]);
971
+ const targetIsStore = Boolean(target.constructor?.[IsStore]);
950
972
  const meta = {
951
973
  deep,
952
974
  scope,
@@ -995,7 +1017,7 @@ const deepSignal = (target, scope, deep = true) => {
995
1017
  if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === "function") {
996
1018
  return Reflect.set(obj, prop, value, receiver);
997
1019
  }
998
- batch.start();
1020
+ batchStart();
999
1021
  const success = Reflect.set(obj, prop, value, receiver);
1000
1022
  const cell = cells.get(prop);
1001
1023
  if (cell) {
@@ -1006,7 +1028,7 @@ const deepSignal = (target, scope, deep = true) => {
1006
1028
  } else {
1007
1029
  triggerIter(obj, prop, value, receiver);
1008
1030
  }
1009
- batch.end();
1031
+ batchEnd();
1010
1032
  return success;
1011
1033
  },
1012
1034
  // 【核心修改】拦截 delete 操作
@@ -1035,10 +1057,14 @@ const shareSignal = (from, fromPath, to, toPath) => {
1035
1057
  const toPaths = toPath.split(".");
1036
1058
  const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
1037
1059
  runWithPulling(() => {
1038
- const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
1060
+ const _getTargetAndKey = getTargetAndKey(from, formPaths),
1061
+ fromTarget = _getTargetAndKey.target,
1062
+ fromKey = _getTargetAndKey.key;
1039
1063
  const val = fromTarget[fromKey];
1040
1064
  const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
1041
- const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1065
+ const _getTargetAndKey2 = getTargetAndKey(to, toPaths),
1066
+ toTarget = _getTargetAndKey2.target,
1067
+ toKey = _getTargetAndKey2.key;
1042
1068
  toTarget[Keys.Meta].cells.set(toKey, fromSignal);
1043
1069
  toTarget[Keys.Raw][toKey] = val;
1044
1070
  }, null);
@@ -1057,13 +1083,16 @@ function getTargetAndKey(obj, paths) {
1057
1083
  target = target[key];
1058
1084
  }
1059
1085
  }
1060
- return { target, key };
1086
+ return {
1087
+ target,
1088
+ key
1089
+ };
1061
1090
  }
1062
1091
  function isIgnoreKey(ignores, key) {
1063
1092
  if (typeof key !== "string") {
1064
1093
  return ignores.includes(key);
1065
1094
  }
1066
- return ignores.some((it) => typeof it === "string" && key.startsWith(it));
1095
+ return ignores.some(it => typeof it === "string" && key.startsWith(it));
1067
1096
  }
1068
1097
  function handleGetterAsComputed(obj, prop, receiver, cells, scope) {
1069
1098
  let s = cells.get(prop);
@@ -1092,18 +1121,18 @@ function triggerIter(obj, prop, value, receiver) {
1092
1121
  }
1093
1122
  }
1094
1123
  const arrayMethodReWrites = {};
1095
- ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach((key) => {
1096
- arrayMethodReWrites[key] = function(...args) {
1097
- batch.start();
1124
+ ["pop", "push", "shift", "splice", "unshift", "copyWithin", "reverse", "fill"].forEach(key => {
1125
+ arrayMethodReWrites[key] = function (...args) {
1126
+ batchStart();
1098
1127
  const fn = Array.prototype[key];
1099
1128
  const res = runWithPulling(() => fn.call(this, ...args), null);
1100
1129
  this[Keys.Iterator] = (this[Keys.Raw][Keys.Iterator] || 0) + 1;
1101
- batch.end();
1130
+ batchEnd();
1102
1131
  return res;
1103
1132
  };
1104
1133
  });
1105
- ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
1106
- arrayMethodReWrites[key] = function(...args) {
1134
+ ["includes", "indexOf", "lastIndexOf"].forEach(key => {
1135
+ arrayMethodReWrites[key] = function (...args) {
1107
1136
  const fn = Array.prototype[key];
1108
1137
  const that = toRaw(this);
1109
1138
  let result = fn.call(that, ...args);
@@ -1123,14 +1152,15 @@ const arrayMethodReWrites = {};
1123
1152
  return result;
1124
1153
  };
1125
1154
  });
1126
- [Symbol.iterator, "values", "entries"].forEach((key) => {
1155
+ [Symbol.iterator, "values", "entries"].forEach(key => {
1127
1156
  const isEntries = key === "entries";
1128
- arrayMethodReWrites[key] = function(...args) {
1157
+ arrayMethodReWrites[key] = function (...args) {
1129
1158
  const fn = Array.prototype[key];
1130
1159
  const rawArray = toRaw(this);
1131
1160
  const iter = fn.call(rawArray, ...args);
1132
1161
  const meta = this[Keys.Meta];
1133
- const { deep: isDeep, scope } = meta;
1162
+ const isDeep = meta.deep,
1163
+ scope = meta.scope;
1134
1164
  if (isDeep) {
1135
1165
  const rawNext = iter.next.bind(iter);
1136
1166
  iter.next = () => {
@@ -1149,9 +1179,10 @@ const arrayMethodReWrites = {};
1149
1179
  return iter;
1150
1180
  };
1151
1181
  });
1152
- arrayMethodReWrites.filter = function(callback, thisArg) {
1182
+ arrayMethodReWrites.filter = function (callback, thisArg) {
1153
1183
  const meta = this[Keys.Meta];
1154
- const { deep: isDeep, scope } = meta;
1184
+ const isDeep = meta.deep,
1185
+ scope = meta.scope;
1155
1186
  const that = toRaw(this);
1156
1187
  const result = [];
1157
1188
  let resultIndex = 0;
@@ -1168,9 +1199,10 @@ arrayMethodReWrites.filter = function(callback, thisArg) {
1168
1199
  this[Keys.Iterator];
1169
1200
  return result;
1170
1201
  };
1171
- arrayMethodReWrites.slice = function(start, end) {
1202
+ arrayMethodReWrites.slice = function (start, end) {
1172
1203
  const meta = this[Keys.Meta];
1173
- const { deep: isDeep, scope } = meta;
1204
+ const isDeep = meta.deep,
1205
+ scope = meta.scope;
1174
1206
  const that = toRaw(this);
1175
1207
  const len = that.length;
1176
1208
  let k = start || 0;
@@ -1195,9 +1227,10 @@ arrayMethodReWrites.slice = function(start, end) {
1195
1227
  this[Keys.Iterator];
1196
1228
  return result;
1197
1229
  };
1198
- arrayMethodReWrites.toReversed = function() {
1230
+ arrayMethodReWrites.toReversed = function () {
1199
1231
  const meta = this[Keys.Meta];
1200
- const { deep: isDeep, scope } = meta;
1232
+ const isDeep = meta.deep,
1233
+ scope = meta.scope;
1201
1234
  const that = toRaw(this);
1202
1235
  const len = that.length;
1203
1236
  const result = new Array(len);
@@ -1209,9 +1242,10 @@ arrayMethodReWrites.toReversed = function() {
1209
1242
  this[Keys.Iterator];
1210
1243
  return result;
1211
1244
  };
1212
- arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1245
+ arrayMethodReWrites.toSpliced = function (start, deleteCount, ...items) {
1213
1246
  const meta = this[Keys.Meta];
1214
- const { deep: isDeep, scope } = meta;
1247
+ const isDeep = meta.deep,
1248
+ scope = meta.scope;
1215
1249
  const that = toRaw(this);
1216
1250
  const len = that.length;
1217
1251
  let relativeStart = start >> 0;
@@ -1242,9 +1276,10 @@ arrayMethodReWrites.toSpliced = function(start, deleteCount, ...items) {
1242
1276
  this[Keys.Iterator];
1243
1277
  return result;
1244
1278
  };
1245
- arrayMethodReWrites.with = function(index, value) {
1279
+ arrayMethodReWrites.with = function (index, value) {
1246
1280
  const meta = this[Keys.Meta];
1247
- const { deep: isDeep, scope } = meta;
1281
+ const isDeep = meta.deep,
1282
+ scope = meta.scope;
1248
1283
  const that = toRaw(this);
1249
1284
  const len = that.length;
1250
1285
  let relativeIndex = Number(index) || 0;
@@ -1263,9 +1298,10 @@ arrayMethodReWrites.with = function(index, value) {
1263
1298
  this[Keys.Iterator];
1264
1299
  return result;
1265
1300
  };
1266
- arrayMethodReWrites.concat = function(...items) {
1301
+ arrayMethodReWrites.concat = function (...items) {
1267
1302
  const meta = this[Keys.Meta];
1268
- const { deep: isDeep, scope } = meta;
1303
+ const isDeep = meta.deep,
1304
+ scope = meta.scope;
1269
1305
  const that = toRaw(this);
1270
1306
  const selfLen = that.length;
1271
1307
  let totalLength = selfLen;
@@ -1305,49 +1341,50 @@ const GetMethodConf = {
1305
1341
  wrapReturn: false,
1306
1342
  wrapArgs: 1
1307
1343
  };
1308
- [
1309
- __spreadValues$1({
1310
- key: "every"
1311
- }, GetMethodConf),
1312
- __spreadValues$1({
1313
- key: "find",
1314
- wrapReturn: true
1315
- }, GetMethodConf),
1316
- __spreadProps(__spreadValues$1({
1317
- key: "findLast"
1318
- }, GetMethodConf), {
1319
- wrapReturn: true
1320
- }),
1321
- __spreadValues$1({
1322
- key: "findIndex"
1323
- }, GetMethodConf),
1324
- __spreadValues$1({
1325
- key: "findLastIndex"
1326
- }, GetMethodConf),
1327
- __spreadValues$1({
1328
- key: "forEach"
1329
- }, GetMethodConf),
1330
- __spreadValues$1({
1331
- key: "map"
1332
- }, GetMethodConf),
1333
- __spreadValues$1({
1334
- key: "some"
1335
- }, GetMethodConf),
1336
- __spreadProps(__spreadValues$1({
1337
- key: "reduce"
1338
- }, GetMethodConf), {
1339
- wrapArgs: 2
1340
- }),
1341
- __spreadProps(__spreadValues$1({
1342
- key: "reduceRight"
1343
- }, GetMethodConf), {
1344
- wrapArgs: 2
1345
- })
1346
- ].forEach(({ key, wrapReturn, wrapArgs }) => {
1347
- arrayMethodReWrites[key] = function(...args) {
1344
+ [{
1345
+ key: "every",
1346
+ ...GetMethodConf
1347
+ }, {
1348
+ key: "find",
1349
+ wrapReturn: true,
1350
+ ...GetMethodConf
1351
+ }, {
1352
+ key: "findLast",
1353
+ ...GetMethodConf,
1354
+ wrapReturn: true
1355
+ }, {
1356
+ key: "findIndex",
1357
+ ...GetMethodConf
1358
+ }, {
1359
+ key: "findLastIndex",
1360
+ ...GetMethodConf
1361
+ }, {
1362
+ key: "forEach",
1363
+ ...GetMethodConf
1364
+ }, {
1365
+ key: "map",
1366
+ ...GetMethodConf
1367
+ }, {
1368
+ key: "some",
1369
+ ...GetMethodConf
1370
+ }, {
1371
+ key: "reduce",
1372
+ ...GetMethodConf,
1373
+ wrapArgs: 2
1374
+ }, {
1375
+ key: "reduceRight",
1376
+ ...GetMethodConf,
1377
+ wrapArgs: 2
1378
+ }].forEach(({
1379
+ key,
1380
+ wrapReturn,
1381
+ wrapArgs
1382
+ }) => {
1383
+ arrayMethodReWrites[key] = function (...args) {
1348
1384
  const meta = this[Keys.Meta];
1349
1385
  const fn = Array.prototype[key];
1350
- const { deep: isDeep, scope } = meta;
1386
+ const isDeep = meta.deep,
1387
+ scope = meta.scope;
1351
1388
  const that = toRaw(this);
1352
1389
  warpCallbackArgs(isDeep, args, scope, wrapArgs);
1353
1390
  let result = fn.call(that, ...args);
@@ -1358,18 +1395,19 @@ const GetMethodConf = {
1358
1395
  return result;
1359
1396
  };
1360
1397
  });
1361
- arrayMethodReWrites.toSorted = function(...args) {
1398
+ arrayMethodReWrites.toSorted = function (...args) {
1362
1399
  const fn = Array.prototype["toSorted"];
1363
1400
  const meta = this[Keys.Meta];
1364
- const { deep: isDeep, scope } = meta;
1401
+ const isDeep = meta.deep,
1402
+ scope = meta.scope;
1365
1403
  const that = toRaw(this);
1366
1404
  warpCallbackArgs(isDeep, args, scope, 3);
1367
1405
  let result = fn.call(that, ...args);
1368
1406
  this[Keys.Iterator];
1369
- return isDeep ? result.map((it) => deepSignal(it, scope)) : result;
1407
+ return isDeep ? result.map(it => deepSignal(it, scope)) : result;
1370
1408
  };
1371
- ["join", "toString", "toLocaleString"].forEach((key) => {
1372
- arrayMethodReWrites[key] = function(...args) {
1409
+ ["join", "toString", "toLocaleString"].forEach(key => {
1410
+ arrayMethodReWrites[key] = function (...args) {
1373
1411
  const fn = Array.prototype[key];
1374
1412
  const that = toRaw(this);
1375
1413
  const result = fn.call(that, ...args);
@@ -1379,7 +1417,7 @@ arrayMethodReWrites.toSorted = function(...args) {
1379
1417
  });
1380
1418
  function warpCallbackArgs(isDeep, args, scope, wrapArgs = 1) {
1381
1419
  const callback = args[0];
1382
- const wrapCb = function(...cbArgs) {
1420
+ const wrapCb = function (...cbArgs) {
1383
1421
  if (isDeep) {
1384
1422
  if (wrapArgs & 1) cbArgs[0] = deepSignal(cbArgs[0], scope);
1385
1423
  if (wrapArgs & 2) cbArgs[1] = deepSignal(cbArgs[1], scope);
@@ -1398,6 +1436,15 @@ const _Store = class _Store {
1398
1436
  _Store.Current = proxy;
1399
1437
  return proxy;
1400
1438
  }
1439
+ static {
1440
+ this[_b] = true;
1441
+ }
1442
+ static {
1443
+ this[_a] = ["ui", "raw"];
1444
+ }
1445
+ static {
1446
+ this.Current = null;
1447
+ }
1401
1448
  static new(keyMap = {}, staticMap = {}) {
1402
1449
  const parentStore = _Store.Current;
1403
1450
  const child = new this();
@@ -1426,27 +1473,8 @@ const _Store = class _Store {
1426
1473
  this.parent = null;
1427
1474
  }
1428
1475
  };
1429
- _Store[_b] = true;
1430
- _Store[_a] = ["ui", "raw"];
1431
- _Store.Current = null;
1432
1476
  let Store = _Store;
1433
1477
 
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
1478
  const DefaultCustomSignalOpt = {
1451
1479
  /** 三种模式
1452
1480
  * 1. auto: 根据值类型自动判断 默认
@@ -1460,7 +1488,10 @@ const DefaultCustomSignalOpt = {
1460
1488
  ({
1461
1489
  scheduler: Scheduler.Sync});
1462
1490
  const $ = (init, opt = {}) => {
1463
- opt = __spreadValues(__spreadValues({}, DefaultCustomSignalOpt), opt);
1491
+ opt = {
1492
+ ...DefaultCustomSignalOpt,
1493
+ ...opt
1494
+ };
1464
1495
  let intiValue, customPull;
1465
1496
  if (typeof init === "function") {
1466
1497
  intiValue = null;
@@ -1478,15 +1509,15 @@ const $ = (init, opt = {}) => {
1478
1509
  return s;
1479
1510
  };
1480
1511
  const effect = (customPull, depOrOpt, opt) => {
1481
- var _a;
1482
1512
  const hasDep = Array.isArray(depOrOpt);
1483
1513
  opt = hasDep ? opt || {} : depOrOpt || {};
1484
1514
  if (!hasDep) {
1485
- const s2 = Signal.create(null, __spreadValues({
1515
+ const s2 = Signal.create(null, {
1486
1516
  customPull,
1487
1517
  scheduler: Scheduler.Sync,
1488
- isScope: true
1489
- }, opt));
1518
+ isScope: true,
1519
+ ...opt
1520
+ });
1490
1521
  s2.v;
1491
1522
  const bound2 = dispose.bind(s2);
1492
1523
  bound2.ins = s2;
@@ -1494,9 +1525,14 @@ const effect = (customPull, depOrOpt, opt) => {
1494
1525
  }
1495
1526
  let mounted = false;
1496
1527
  const deps = depOrOpt;
1497
- const immediate = deps.length === 0 ? true : (_a = opt.immediate) != null ? _a : true;
1498
- const vs = Array.from({ length: deps.length }, () => ({ old: null, val: null }));
1499
- const s = Signal.create(null, __spreadValues({
1528
+ const immediate = deps.length === 0 ? true : opt.immediate ?? true;
1529
+ const vs = Array.from({
1530
+ length: deps.length
1531
+ }, () => ({
1532
+ old: null,
1533
+ val: null
1534
+ }));
1535
+ const s = Signal.create(null, {
1500
1536
  customPull() {
1501
1537
  for (let i = 0; i < deps.length; i++) {
1502
1538
  const value = deps[i].v;
@@ -1511,8 +1547,9 @@ const effect = (customPull, depOrOpt, opt) => {
1511
1547
  mounted = true;
1512
1548
  },
1513
1549
  scheduler: Scheduler.Sync,
1514
- isScope: true
1515
- }, opt));
1550
+ isScope: true,
1551
+ ...opt
1552
+ });
1516
1553
  s.v;
1517
1554
  const bound = dispose.bind(s);
1518
1555
  bound.ins = s;
@@ -1538,15 +1575,18 @@ const scope = (...args) => {
1538
1575
  bound.ins = s;
1539
1576
  return bound;
1540
1577
  };
1541
- const customEffect = (opt) => {
1542
- return ((init, innerOpt = {}) => {
1543
- return effect(init, __spreadValues(__spreadValues({}, opt), innerOpt));
1544
- });
1578
+ const customEffect = opt => {
1579
+ return (init, innerOpt = {}) => {
1580
+ return effect(init, {
1581
+ ...opt,
1582
+ ...innerOpt
1583
+ });
1584
+ };
1545
1585
  };
1546
- const isSignal = (value) => {
1586
+ const isSignal = value => {
1547
1587
  return value instanceof Signal;
1548
1588
  };
1549
- const isScope = (value) => {
1589
+ const isScope = value => {
1550
1590
  return value instanceof Signal;
1551
1591
  };
1552
1592
 
@@ -1558,7 +1598,8 @@ exports.Signal = Signal;
1558
1598
  exports.Store = Store;
1559
1599
  exports.StoreIgnoreKeys = StoreIgnoreKeys;
1560
1600
  exports.TaskQueue = TaskQueue;
1561
- exports.batch = batch;
1601
+ exports.batchEnd = batchEnd;
1602
+ exports.batchStart = batchStart;
1562
1603
  exports.clean = clean;
1563
1604
  exports.customEffect = customEffect;
1564
1605
  exports.deepSignal = deepSignal;