@feng3d/reactivity 1.0.5 → 1.0.7
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/assets/RobotoMono-Medium-DVgDz_OO.woff2 +0 -0
- package/dist/assets/RobotoMono-Regular-BPoF81uy.woff2 +0 -0
- package/dist/assets/index-a2qCSG5V.css +629 -0
- package/dist/assets/index.html-Dyp3udP2.js +200 -0
- package/dist/assets/modulepreload-polyfill-DaKOjhqt.js +37 -0
- package/dist/assets/package-DuJynByc.js +2539 -0
- package/dist/assets/src//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274/index.html-C3hbV3IR.js +59 -0
- package/dist/assets/src//346/225/260/347/273/204/index.html-CHK6WEhd.js +43 -0
- package/dist/docs/.nojekyll +1 -0
- package/dist/docs/assets/hierarchy.js +1 -0
- package/dist/docs/assets/highlight.css +92 -0
- package/dist/docs/assets/icons.js +18 -0
- package/dist/docs/assets/icons.svg +1 -0
- package/dist/docs/assets/main.js +60 -0
- package/dist/docs/assets/navigation.js +1 -0
- package/dist/docs/assets/search.js +1 -0
- package/dist/docs/assets/style.css +1640 -0
- package/dist/docs/classes/EffectScope.html +40 -0
- package/dist/docs/functions/batchRun.html +15 -0
- package/dist/docs/functions/computed.html +5 -0
- package/dist/docs/functions/effect.html +11 -0
- package/dist/docs/functions/effectScope.html +5 -0
- package/dist/docs/functions/forceTrack.html +6 -0
- package/dist/docs/functions/getCurrentScope.html +4 -0
- package/dist/docs/functions/isProxy.html +5 -0
- package/dist/docs/functions/isReactive.html +5 -0
- package/dist/docs/functions/isRef.html +5 -0
- package/dist/docs/functions/noTrack.html +6 -0
- package/dist/docs/functions/onScopeDispose.html +6 -0
- package/dist/docs/functions/reactive.html +19 -0
- package/dist/docs/functions/ref.html +13 -0
- package/dist/docs/functions/toRaw.html +4 -0
- package/dist/docs/hierarchy.html +1 -0
- package/dist/docs/index.html +129 -0
- package/dist/docs/interfaces/Computed.html +9 -0
- package/dist/docs/interfaces/Effect.html +8 -0
- package/dist/docs/interfaces/Ref.html +9 -0
- package/dist/docs/modules.html +1 -0
- package/dist/docs/types/Reactive.html +3 -0
- package/dist/docs/types/UnReadonly.html +3 -0
- package/dist/files/RobotoMono-Medium.woff2 +0 -0
- package/dist/files/RobotoMono-Regular.woff2 +0 -0
- package/dist/files/ic_code_black_24dp.svg +4 -0
- package/dist/files/ic_search_black_24dp.svg +4 -0
- package/dist/files/main.css +629 -0
- package/dist/files/thumbnails.svg +7 -0
- package/dist/files.json +7 -0
- package/dist/index.html +84 -0
- package/dist/index.js +733 -157
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +733 -157
- package/dist/index.umd.cjs.map +1 -1
- package/dist/screenshots//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274.jpg +0 -0
- package/dist/screenshots//346/225/260/347/273/204.jpg +0 -0
- package/dist/src//345/244/215/346/235/202/346/203/205/345/206/265/345/217/226/345/200/274/index.html +70 -0
- package/dist/src//346/225/260/347/273/204/index.html +65 -0
- package/dist/tags.json +2 -0
- package/lib/Reactivity.d.ts +47 -13
- package/lib/Reactivity.d.ts.map +1 -1
- package/lib/arrayInstrumentations.d.ts +10 -0
- package/lib/arrayInstrumentations.d.ts.map +1 -1
- package/lib/baseHandlers.d.ts +3 -1
- package/lib/baseHandlers.d.ts.map +1 -1
- package/lib/batch.d.ts +17 -5
- package/lib/batch.d.ts.map +1 -1
- package/lib/collectionHandlers.d.ts +21 -0
- package/lib/collectionHandlers.d.ts.map +1 -1
- package/lib/computed.d.ts +75 -27
- package/lib/computed.d.ts.map +1 -1
- package/lib/effect.d.ts +25 -0
- package/lib/effect.d.ts.map +1 -1
- package/lib/effectScope.d.ts +129 -0
- package/lib/effectScope.d.ts.map +1 -0
- package/lib/index.d.ts +6 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/property.d.ts.map +1 -1
- package/lib/reactive.d.ts +58 -17
- package/lib/reactive.d.ts.map +1 -1
- package/lib/ref.d.ts +66 -4
- package/lib/ref.d.ts.map +1 -1
- package/lib/shared/constants.d.ts +7 -7
- package/lib/shared/constants.d.ts.map +1 -1
- package/lib/shared/general.d.ts +1 -1
- package/lib/shared/general.d.ts.map +1 -1
- package/package.json +19 -17
- package/src/Reactivity.ts +57 -15
- package/src/arrayInstrumentations.ts +406 -53
- package/src/baseHandlers.ts +124 -32
- package/src/batch.ts +38 -11
- package/src/collectionHandlers.ts +207 -19
- package/src/computed.ts +92 -43
- package/src/effect.ts +38 -0
- package/src/effectScope.ts +294 -0
- package/src/index.ts +6 -5
- package/src/property.ts +6 -0
- package/src/reactive.ts +67 -20
- package/src/ref.ts +66 -4
package/src/baseHandlers.ts
CHANGED
|
@@ -7,74 +7,93 @@ import { PropertyReactivity } from './property';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 基础响应式处理器。
|
|
10
|
+
*
|
|
11
|
+
* 实现了 Proxy 的 get 拦截器,用于:
|
|
12
|
+
* 1. 响应式对象的标识和原始对象获取
|
|
13
|
+
* 2. 数组方法的特殊处理
|
|
14
|
+
* 3. 属性的依赖追踪
|
|
15
|
+
* 4. 值的自动解包和响应式转换
|
|
10
16
|
*/
|
|
11
17
|
class BaseReactiveHandler implements ProxyHandler<Target>
|
|
12
18
|
{
|
|
13
19
|
/**
|
|
14
20
|
* 获取对象的属性值。
|
|
15
21
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
22
|
+
* 实现了以下功能:
|
|
23
|
+
* 1. 响应式对象标识检查
|
|
24
|
+
* 2. 原始对象获取
|
|
25
|
+
* 3. 数组方法拦截
|
|
26
|
+
* 4. 属性依赖追踪
|
|
27
|
+
* 5. 值的自动解包
|
|
28
|
+
* 6. 对象的自动响应式转换
|
|
29
|
+
*
|
|
30
|
+
* @param target 被代理的原始对象
|
|
31
|
+
* @param key 要获取的属性名
|
|
32
|
+
* @param receiver 代理对象本身
|
|
33
|
+
* @returns 获取到的属性值
|
|
20
34
|
*/
|
|
21
35
|
get(target: Target, key: string | symbol, receiver: object): any
|
|
22
36
|
{
|
|
23
|
-
//
|
|
24
|
-
if (key === ReactiveFlags.IS_REACTIVE)
|
|
37
|
+
// 检查是否为响应式对象
|
|
38
|
+
if (key === ReactiveFlags.IS_REACTIVE)
|
|
25
39
|
{
|
|
26
40
|
return true;
|
|
27
41
|
}
|
|
28
|
-
|
|
42
|
+
// 获取原始对象
|
|
43
|
+
else if (key === ReactiveFlags.RAW)
|
|
29
44
|
{
|
|
30
45
|
if (
|
|
31
|
-
receiver
|
|
32
|
-
|
|
33
|
-
// receiver
|
|
34
|
-
// this means the receiver is a user proxy of the reactive proxy
|
|
46
|
+
receiver === reactiveMap.get(target)
|
|
47
|
+
// receiver 不是响应式代理,但具有相同的原型
|
|
48
|
+
// 这意味着 receiver 是响应式代理的用户代理
|
|
35
49
|
|| Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)
|
|
36
50
|
)
|
|
37
51
|
{
|
|
38
52
|
return target;
|
|
39
53
|
}
|
|
40
|
-
// early return undefined
|
|
41
54
|
|
|
55
|
+
// 提前返回 undefined
|
|
42
56
|
return;
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
const targetIsArray = isArray(target);
|
|
46
60
|
|
|
61
|
+
// 处理数组方法
|
|
47
62
|
let fn: Function | undefined;
|
|
63
|
+
|
|
48
64
|
if (targetIsArray && (fn = arrayInstrumentations[key]))
|
|
49
65
|
{
|
|
50
66
|
return fn;
|
|
51
67
|
}
|
|
68
|
+
// 处理 hasOwnProperty 方法
|
|
52
69
|
if (key === 'hasOwnProperty')
|
|
53
70
|
{
|
|
54
71
|
return hasOwnProperty;
|
|
55
72
|
}
|
|
56
73
|
|
|
74
|
+
// 获取属性值
|
|
57
75
|
const res = Reflect.get(
|
|
58
76
|
target,
|
|
59
77
|
key,
|
|
60
78
|
isRef(target) ? target : receiver,
|
|
61
79
|
);
|
|
62
80
|
|
|
81
|
+
// 跳过内置 Symbol 和非追踪键的依赖追踪
|
|
63
82
|
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key))
|
|
64
83
|
{
|
|
65
84
|
return res;
|
|
66
85
|
}
|
|
67
86
|
|
|
68
|
-
//
|
|
87
|
+
// 追踪属性访问
|
|
69
88
|
PropertyReactivity.track(target, TrackOpTypes.GET, key as any);
|
|
70
89
|
|
|
71
|
-
//
|
|
90
|
+
// 自动解包 ref 值
|
|
72
91
|
if (isRef(res))
|
|
73
92
|
{
|
|
74
93
|
return targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
//
|
|
96
|
+
// 自动转换对象为响应式
|
|
78
97
|
if (isObject(res))
|
|
79
98
|
{
|
|
80
99
|
return reactive(res);
|
|
@@ -86,16 +105,29 @@ class BaseReactiveHandler implements ProxyHandler<Target>
|
|
|
86
105
|
|
|
87
106
|
/**
|
|
88
107
|
* 可变响应式处理器。
|
|
108
|
+
*
|
|
109
|
+
* 继承自基础响应式处理器,增加了:
|
|
110
|
+
* 1. 属性设置拦截
|
|
111
|
+
* 2. 属性删除拦截
|
|
112
|
+
* 3. 属性存在性检查拦截
|
|
113
|
+
* 4. 属性遍历拦截
|
|
89
114
|
*/
|
|
90
115
|
class MutableReactiveHandler extends BaseReactiveHandler
|
|
91
116
|
{
|
|
92
117
|
/**
|
|
93
118
|
* 设置对象的属性值。
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
119
|
+
*
|
|
120
|
+
* 实现了以下功能:
|
|
121
|
+
* 1. 值的原始化处理
|
|
122
|
+
* 2. ref 值的特殊处理
|
|
123
|
+
* 3. 属性变更通知
|
|
124
|
+
* 4. 数组长度的特殊处理
|
|
125
|
+
*
|
|
126
|
+
* @param target 被代理的原始对象
|
|
127
|
+
* @param key 要设置的属性名
|
|
128
|
+
* @param value 要设置的新值
|
|
129
|
+
* @param receiver 代理对象本身
|
|
130
|
+
* @returns 设置是否成功
|
|
99
131
|
*/
|
|
100
132
|
set(
|
|
101
133
|
target: Record<string | symbol, unknown>,
|
|
@@ -106,9 +138,11 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
106
138
|
{
|
|
107
139
|
let oldValue = target[key];
|
|
108
140
|
|
|
141
|
+
// 获取原始值进行比较
|
|
109
142
|
oldValue = toRaw(oldValue);
|
|
110
143
|
value = toRaw(value);
|
|
111
144
|
|
|
145
|
+
// 处理 ref 值的特殊情况
|
|
112
146
|
if (!isArray(target) && isRef(oldValue) && !isRef(value))
|
|
113
147
|
{
|
|
114
148
|
oldValue.value = value;
|
|
@@ -116,6 +150,7 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
116
150
|
return true;
|
|
117
151
|
}
|
|
118
152
|
|
|
153
|
+
// 检查属性是否存在
|
|
119
154
|
const hadKey
|
|
120
155
|
= isArray(target) && isIntegerKey(key)
|
|
121
156
|
? Number(key) < target.length
|
|
@@ -126,18 +161,21 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
126
161
|
value,
|
|
127
162
|
isRef(target) ? target : receiver,
|
|
128
163
|
);
|
|
129
|
-
|
|
164
|
+
|
|
165
|
+
// 确保目标在原始原型链中
|
|
130
166
|
__DEV__ && console.assert(target === toRaw(receiver));
|
|
131
167
|
|
|
132
|
-
//
|
|
168
|
+
// 触发属性变更通知
|
|
133
169
|
if (target === toRaw(receiver))
|
|
134
170
|
{
|
|
135
171
|
if (!hadKey)
|
|
136
172
|
{
|
|
173
|
+
// 新增属性
|
|
137
174
|
PropertyReactivity.trigger(target, TriggerOpTypes.ADD, key, value);
|
|
138
175
|
}
|
|
139
176
|
else if (hasChanged(value, oldValue))
|
|
140
177
|
{
|
|
178
|
+
// 修改属性
|
|
141
179
|
PropertyReactivity.trigger(target, TriggerOpTypes.SET, key, value, oldValue);
|
|
142
180
|
}
|
|
143
181
|
}
|
|
@@ -148,9 +186,13 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
148
186
|
/**
|
|
149
187
|
* 删除对象的属性。
|
|
150
188
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
189
|
+
* 实现了以下功能:
|
|
190
|
+
* 1. 属性删除操作
|
|
191
|
+
* 2. 删除后的变更通知
|
|
192
|
+
*
|
|
193
|
+
* @param target 被代理的原始对象
|
|
194
|
+
* @param key 要删除的属性名
|
|
195
|
+
* @returns 删除是否成功
|
|
154
196
|
*/
|
|
155
197
|
deleteProperty(
|
|
156
198
|
target: Record<string | symbol, unknown>,
|
|
@@ -160,27 +202,53 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
160
202
|
const hadKey = hasOwn(target, key);
|
|
161
203
|
const oldValue = target[key];
|
|
162
204
|
const result = Reflect.deleteProperty(target, key);
|
|
205
|
+
|
|
163
206
|
if (result && hadKey)
|
|
164
207
|
{
|
|
208
|
+
// 触发删除通知
|
|
165
209
|
PropertyReactivity.trigger(target, TriggerOpTypes.DELETE, key, undefined, oldValue);
|
|
166
210
|
}
|
|
167
211
|
|
|
168
212
|
return result;
|
|
169
213
|
}
|
|
170
214
|
|
|
215
|
+
/**
|
|
216
|
+
* 检查对象是否包含某个属性。
|
|
217
|
+
*
|
|
218
|
+
* 实现了以下功能:
|
|
219
|
+
* 1. 属性存在性检查
|
|
220
|
+
* 2. 属性访问依赖追踪
|
|
221
|
+
*
|
|
222
|
+
* @param target 被代理的原始对象
|
|
223
|
+
* @param key 要检查的属性名
|
|
224
|
+
* @returns 属性是否存在
|
|
225
|
+
*/
|
|
171
226
|
has(target: Record<string | symbol, unknown>, key: string | symbol): boolean
|
|
172
227
|
{
|
|
173
228
|
const result = Reflect.has(target, key);
|
|
229
|
+
|
|
174
230
|
if (!isSymbol(key) || !builtInSymbols.has(key))
|
|
175
231
|
{
|
|
232
|
+
// 追踪属性访问
|
|
176
233
|
PropertyReactivity.track(target, TrackOpTypes.HAS, key);
|
|
177
234
|
}
|
|
178
235
|
|
|
179
236
|
return result;
|
|
180
237
|
}
|
|
181
238
|
|
|
239
|
+
/**
|
|
240
|
+
* 获取对象的所有属性名。
|
|
241
|
+
*
|
|
242
|
+
* 实现了以下功能:
|
|
243
|
+
* 1. 属性遍历
|
|
244
|
+
* 2. 遍历操作的依赖追踪
|
|
245
|
+
*
|
|
246
|
+
* @param target 被代理的原始对象
|
|
247
|
+
* @returns 对象的所有属性名数组
|
|
248
|
+
*/
|
|
182
249
|
ownKeys(target: Record<string | symbol, unknown>): (string | symbol)[]
|
|
183
250
|
{
|
|
251
|
+
// 追踪遍历操作
|
|
184
252
|
PropertyReactivity.track(
|
|
185
253
|
target,
|
|
186
254
|
TrackOpTypes.ITERATE,
|
|
@@ -192,29 +260,53 @@ class MutableReactiveHandler extends BaseReactiveHandler
|
|
|
192
260
|
}
|
|
193
261
|
|
|
194
262
|
/**
|
|
195
|
-
*
|
|
263
|
+
* 可变响应式处理器实例。
|
|
264
|
+
*
|
|
265
|
+
* 用于创建可变的响应式对象。
|
|
196
266
|
*/
|
|
197
267
|
export const mutableHandlers: ProxyHandler<object> = new MutableReactiveHandler();
|
|
198
268
|
|
|
269
|
+
/**
|
|
270
|
+
* 自定义 hasOwnProperty 方法。
|
|
271
|
+
*
|
|
272
|
+
* 实现了以下功能:
|
|
273
|
+
* 1. 属性存在性检查
|
|
274
|
+
* 2. 属性访问依赖追踪
|
|
275
|
+
*
|
|
276
|
+
* @param this 调用对象
|
|
277
|
+
* @param key 要检查的属性名
|
|
278
|
+
* @returns 属性是否存在
|
|
279
|
+
*/
|
|
199
280
|
function hasOwnProperty(this: object, key: unknown)
|
|
200
281
|
{
|
|
201
|
-
// #10455 hasOwnProperty
|
|
282
|
+
// #10455 hasOwnProperty 可能被非字符串值调用
|
|
202
283
|
if (!isSymbol(key)) key = String(key);
|
|
203
284
|
const obj = toRaw(this);
|
|
285
|
+
|
|
286
|
+
// 追踪属性访问
|
|
204
287
|
PropertyReactivity.track(obj, TrackOpTypes.HAS, key);
|
|
205
288
|
|
|
206
289
|
return obj.hasOwnProperty(key as string);
|
|
207
290
|
}
|
|
208
291
|
|
|
292
|
+
/**
|
|
293
|
+
* 内置 Symbol 集合。
|
|
294
|
+
*
|
|
295
|
+
* 用于过滤不需要追踪的 Symbol 属性。
|
|
296
|
+
*/
|
|
209
297
|
const builtInSymbols = new Set(
|
|
210
|
-
/* @__PURE__*/
|
|
298
|
+
/* @__PURE__ */
|
|
211
299
|
Object.getOwnPropertyNames(Symbol)
|
|
212
|
-
// ios10.x Object.getOwnPropertyNames(Symbol)
|
|
213
|
-
//
|
|
214
|
-
// function
|
|
300
|
+
// ios10.x Object.getOwnPropertyNames(Symbol) 可以枚举 'arguments' 和 'caller'
|
|
301
|
+
// 但在 Symbol 上访问它们会导致 TypeError,因为 Symbol 是严格模式函数
|
|
215
302
|
.filter((key) => key !== 'arguments' && key !== 'caller')
|
|
216
303
|
.map((key) => Symbol[key as keyof SymbolConstructor])
|
|
217
304
|
.filter(isSymbol),
|
|
218
305
|
);
|
|
219
306
|
|
|
220
|
-
|
|
307
|
+
/**
|
|
308
|
+
* 非追踪键集合。
|
|
309
|
+
*
|
|
310
|
+
* 用于过滤不需要追踪的属性名。
|
|
311
|
+
*/
|
|
312
|
+
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
package/src/batch.ts
CHANGED
|
@@ -2,10 +2,14 @@ import { ComputedReactivity } from './computed';
|
|
|
2
2
|
import { Reactivity } from './Reactivity';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 合批处理依赖。
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* 将依赖添加到待处理队列中,根据依赖的运行状态决定处理方式:
|
|
8
|
+
* 1. 如果依赖正在运行,添加到已运行队列
|
|
9
|
+
* 2. 如果依赖未运行,添加到待运行队列
|
|
10
|
+
*
|
|
11
|
+
* @param dep 要处理的依赖
|
|
12
|
+
* @param isRunning 依赖是否正在运行
|
|
9
13
|
*/
|
|
10
14
|
export function batch(dep: ComputedReactivity, isRunning: boolean): void
|
|
11
15
|
{
|
|
@@ -20,8 +24,15 @@ export function batch(dep: ComputedReactivity, isRunning: boolean): void
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* 批次执行多次修改反应式对象。
|
|
28
|
+
*
|
|
29
|
+
* 将多个响应式更新合并为一个批次执行,可以减少不必要的反应式触发。
|
|
30
|
+
* 在批次执行期间:
|
|
31
|
+
* 1. 所有响应式更新都会被收集
|
|
32
|
+
* 2. 批次结束后统一处理所有更新
|
|
33
|
+
* 3. 避免中间状态触发不必要的更新
|
|
24
34
|
*
|
|
35
|
+
* 示例:
|
|
25
36
|
* ```ts
|
|
26
37
|
* batchRun(() => {
|
|
27
38
|
* // 修改反应式对象
|
|
@@ -30,7 +41,8 @@ export function batch(dep: ComputedReactivity, isRunning: boolean): void
|
|
|
30
41
|
* })
|
|
31
42
|
* ```
|
|
32
43
|
*
|
|
33
|
-
* @param fn
|
|
44
|
+
* @param fn 要执行的函数,在此函数中多次修改反应式对象
|
|
45
|
+
* @returns 函数的执行结果
|
|
34
46
|
*/
|
|
35
47
|
export function batchRun<T>(fn: () => T): T
|
|
36
48
|
{
|
|
@@ -43,12 +55,12 @@ export function batchRun<T>(fn: () => T): T
|
|
|
43
55
|
return;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
//
|
|
58
|
+
// 处理已经运行过的依赖
|
|
47
59
|
if (_isRunedDeps.length > 0)
|
|
48
60
|
{
|
|
49
61
|
_isRunedDeps.forEach((dep) =>
|
|
50
62
|
{
|
|
51
|
-
//
|
|
63
|
+
// 此时依赖以及子依赖都已经运行过了,只需修复与子节点关系
|
|
52
64
|
__DEV__ && console.assert(dep._isDirty === false, 'dep.dirty === false');
|
|
53
65
|
|
|
54
66
|
// 修复与子节点关系
|
|
@@ -61,13 +73,14 @@ export function batchRun<T>(fn: () => T): T
|
|
|
61
73
|
_isRunedDeps.length = 0;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
|
-
//
|
|
76
|
+
// 批次处理待运行的依赖
|
|
65
77
|
if (_needEffectDeps.length > 0)
|
|
66
78
|
{
|
|
67
79
|
_needEffectDeps.forEach((dep) =>
|
|
68
80
|
{
|
|
69
|
-
//
|
|
81
|
+
// 独立执行回调,避免影响其他依赖
|
|
70
82
|
const pre = Reactivity.activeReactivity;
|
|
83
|
+
|
|
71
84
|
Reactivity.activeReactivity = null;
|
|
72
85
|
|
|
73
86
|
dep.runIfDirty();
|
|
@@ -80,12 +93,26 @@ export function batchRun<T>(fn: () => T): T
|
|
|
80
93
|
return result;
|
|
81
94
|
}
|
|
82
95
|
|
|
96
|
+
/**
|
|
97
|
+
* 批次深度。
|
|
98
|
+
*
|
|
99
|
+
* 用于跟踪嵌套的批次执行。
|
|
100
|
+
* 当深度大于 0 时,表示当前正在批次执行中。
|
|
101
|
+
*/
|
|
83
102
|
let _batchDepth = 0;
|
|
103
|
+
|
|
84
104
|
/**
|
|
85
|
-
*
|
|
105
|
+
* 待运行的依赖队列。
|
|
106
|
+
*
|
|
107
|
+
* 存储需要执行但尚未执行的依赖。
|
|
108
|
+
* 在批次执行结束后,会统一处理这些依赖。
|
|
86
109
|
*/
|
|
87
110
|
const _needEffectDeps: ComputedReactivity[] = [];
|
|
111
|
+
|
|
88
112
|
/**
|
|
89
|
-
*
|
|
113
|
+
* 已运行的依赖队列。
|
|
114
|
+
*
|
|
115
|
+
* 存储已经执行过的依赖。
|
|
116
|
+
* 这些依赖只需要修复与子节点的关系,不需要重新执行。
|
|
90
117
|
*/
|
|
91
118
|
const _isRunedDeps: ComputedReactivity[] = [];
|