wevu 0.0.2-alpha.0 → 1.0.0-alpha.2

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.
@@ -25,6 +25,85 @@ function nextTick(fn) {
25
25
  const targetMap = /* @__PURE__ */ new WeakMap();
26
26
  let activeEffect = null;
27
27
  const effectStack = [];
28
+ let batchDepth = 0;
29
+ const batchedEffects = /* @__PURE__ */ new Set();
30
+ function startBatch() {
31
+ batchDepth++;
32
+ }
33
+ function endBatch() {
34
+ if (batchDepth === 0) return;
35
+ batchDepth--;
36
+ if (batchDepth === 0) flushBatchedEffects();
37
+ }
38
+ function batch(fn) {
39
+ startBatch();
40
+ try {
41
+ return fn();
42
+ } finally {
43
+ endBatch();
44
+ }
45
+ }
46
+ function flushBatchedEffects() {
47
+ while (batchedEffects.size) {
48
+ const effects = Array.from(batchedEffects);
49
+ batchedEffects.clear();
50
+ for (const ef of effects) ef();
51
+ }
52
+ }
53
+ let activeEffectScope;
54
+ var EffectScopeImpl = class {
55
+ active = true;
56
+ effects = [];
57
+ cleanups = [];
58
+ parent;
59
+ scopes;
60
+ constructor(detached = false) {
61
+ this.detached = detached;
62
+ if (!detached && activeEffectScope) {
63
+ this.parent = activeEffectScope;
64
+ (activeEffectScope.scopes ||= []).push(this);
65
+ }
66
+ }
67
+ run(fn) {
68
+ if (!this.active) return;
69
+ const prev = activeEffectScope;
70
+ activeEffectScope = this;
71
+ try {
72
+ return fn();
73
+ } finally {
74
+ activeEffectScope = prev;
75
+ }
76
+ }
77
+ stop() {
78
+ if (!this.active) return;
79
+ this.active = false;
80
+ for (const effect$1 of this.effects) stop(effect$1);
81
+ this.effects.length = 0;
82
+ for (const cleanup of this.cleanups) cleanup();
83
+ this.cleanups.length = 0;
84
+ if (this.scopes) {
85
+ for (const scope of this.scopes) scope.stop();
86
+ this.scopes.length = 0;
87
+ }
88
+ if (this.parent?.scopes) {
89
+ const index = this.parent.scopes.indexOf(this);
90
+ if (index >= 0) this.parent.scopes.splice(index, 1);
91
+ }
92
+ this.parent = void 0;
93
+ }
94
+ };
95
+ function effectScope(detached = false) {
96
+ return new EffectScopeImpl(detached);
97
+ }
98
+ function getCurrentScope() {
99
+ return activeEffectScope;
100
+ }
101
+ function onScopeDispose(fn) {
102
+ if (activeEffectScope?.active) activeEffectScope.cleanups.push(fn);
103
+ }
104
+ function recordEffectScope(effect$1) {
105
+ if (activeEffectScope?.active) activeEffectScope.effects.push(effect$1);
106
+ }
28
107
  function cleanupEffect(effect$1) {
29
108
  const { deps } = effect$1;
30
109
  for (let i = 0; i < deps.length; i++) deps[i].delete(effect$1);
@@ -33,26 +112,30 @@ function cleanupEffect(effect$1) {
33
112
  function createReactiveEffect(fn, options = {}) {
34
113
  const effect$1 = function reactiveEffect() {
35
114
  if (!effect$1.active) return fn();
36
- if (effectStack.includes(effect$1)) return fn();
115
+ if (effect$1._running) return fn();
37
116
  cleanupEffect(effect$1);
38
117
  try {
118
+ effect$1._running = true;
39
119
  effectStack.push(effect$1);
40
120
  activeEffect = effect$1;
41
121
  return fn();
42
122
  } finally {
43
123
  effectStack.pop();
44
124
  activeEffect = effectStack[effectStack.length - 1] ?? null;
125
+ effect$1._running = false;
45
126
  }
46
127
  };
47
128
  effect$1.deps = [];
48
129
  effect$1.scheduler = options.scheduler;
49
130
  effect$1.onStop = options.onStop;
50
131
  effect$1.active = true;
132
+ effect$1._running = false;
51
133
  effect$1._fn = fn;
52
134
  return effect$1;
53
135
  }
54
136
  function effect(fn, options = {}) {
55
137
  const _effect = createReactiveEffect(fn, options);
138
+ recordEffectScope(_effect);
56
139
  if (!options.lazy) _effect();
57
140
  return _effect;
58
141
  }
@@ -88,10 +171,7 @@ function trigger(target, key) {
88
171
  effects.forEach((ef) => {
89
172
  if (ef !== activeEffect) effectsToRun.add(ef);
90
173
  });
91
- effectsToRun.forEach((ef) => {
92
- if (ef.scheduler) ef.scheduler();
93
- else ef();
94
- });
174
+ effectsToRun.forEach(scheduleEffect);
95
175
  }
96
176
  function trackEffects(dep) {
97
177
  if (!activeEffect) return;
@@ -101,10 +181,18 @@ function trackEffects(dep) {
101
181
  }
102
182
  }
103
183
  function triggerEffects(dep) {
104
- dep.forEach((ef) => {
105
- if (ef.scheduler) ef.scheduler();
106
- else ef();
107
- });
184
+ dep.forEach(scheduleEffect);
185
+ }
186
+ function scheduleEffect(ef) {
187
+ if (ef.scheduler) {
188
+ ef.scheduler();
189
+ return;
190
+ }
191
+ if (batchDepth > 0) {
192
+ batchedEffects.add(ef);
193
+ return;
194
+ }
195
+ ef();
108
196
  }
109
197
 
110
198
  //#endregion
@@ -366,7 +454,7 @@ var RefImpl = class {
366
454
  };
367
455
  function ref(value) {
368
456
  if (isRef(value)) return value;
369
- return new RefImpl(value);
457
+ return markRaw(new RefImpl(value));
370
458
  }
371
459
  function unref(value) {
372
460
  return isRef(value) ? value.value : value;
@@ -390,7 +478,7 @@ var CustomRefImpl = class {
390
478
  }
391
479
  };
392
480
  function customRef(factory, defaultValue) {
393
- return new CustomRefImpl(factory, defaultValue);
481
+ return markRaw(new CustomRefImpl(factory, defaultValue));
394
482
  }
395
483
 
396
484
  //#endregion
@@ -636,6 +724,12 @@ function storeToRefs(store) {
636
724
  }
637
725
 
638
726
  //#endregion
727
+ Object.defineProperty(exports, 'batch', {
728
+ enumerable: true,
729
+ get: function () {
730
+ return batch;
731
+ }
732
+ });
639
733
  Object.defineProperty(exports, 'computed', {
640
734
  enumerable: true,
641
735
  get: function () {
@@ -666,6 +760,24 @@ Object.defineProperty(exports, 'effect', {
666
760
  return effect;
667
761
  }
668
762
  });
763
+ Object.defineProperty(exports, 'effectScope', {
764
+ enumerable: true,
765
+ get: function () {
766
+ return effectScope;
767
+ }
768
+ });
769
+ Object.defineProperty(exports, 'endBatch', {
770
+ enumerable: true,
771
+ get: function () {
772
+ return endBatch;
773
+ }
774
+ });
775
+ Object.defineProperty(exports, 'getCurrentScope', {
776
+ enumerable: true,
777
+ get: function () {
778
+ return getCurrentScope;
779
+ }
780
+ });
669
781
  Object.defineProperty(exports, 'isObject', {
670
782
  enumerable: true,
671
783
  get: function () {
@@ -708,6 +820,12 @@ Object.defineProperty(exports, 'nextTick', {
708
820
  return nextTick;
709
821
  }
710
822
  });
823
+ Object.defineProperty(exports, 'onScopeDispose', {
824
+ enumerable: true,
825
+ get: function () {
826
+ return onScopeDispose;
827
+ }
828
+ });
711
829
  Object.defineProperty(exports, 'queueJob', {
712
830
  enumerable: true,
713
831
  get: function () {
@@ -732,6 +850,12 @@ Object.defineProperty(exports, 'shallowReactive', {
732
850
  return shallowReactive;
733
851
  }
734
852
  });
853
+ Object.defineProperty(exports, 'startBatch', {
854
+ enumerable: true,
855
+ get: function () {
856
+ return startBatch;
857
+ }
858
+ });
735
859
  Object.defineProperty(exports, 'stop', {
736
860
  enumerable: true,
737
861
  get: function () {
package/dist/store.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_store = require('./store-Cmw9vWBT.cjs');
1
+ const require_store = require('./store-D0GD8ulz.cjs');
2
2
 
3
3
  exports.createStore = require_store.createStore;
4
4
  exports.defineStore = require_store.defineStore;
package/dist/store.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-D1r6nN-t.cjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-DVEFI-Uo.cjs";
2
2
  export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
package/dist/store.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-DHBSC7mS.mjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-0dF4y5p6.mjs";
2
2
  export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
package/dist/store.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as defineStore, r as createStore, t as storeToRefs } from "./store-BcU7YVhB.mjs";
1
+ import { n as defineStore, r as createStore, t as storeToRefs } from "./store-2q4qcdBi.mjs";
2
2
 
3
3
  export { createStore, defineStore, storeToRefs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wevu",
3
3
  "type": "module",
4
- "version": "0.0.2-alpha.0",
4
+ "version": "1.0.0-alpha.2",
5
5
  "description": "Vue 3 风格的小程序运行时,包含响应式、diff+setData 与轻量状态管理",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",