@lytjs/reactivity 6.0.0 → 6.4.0
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/async.cjs +7 -7
- package/dist/async.cjs.map +1 -1
- package/dist/async.mjs +7 -7
- package/dist/async.mjs.map +1 -1
- package/dist/index.cjs +91 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +89 -20
- package/dist/index.mjs.map +1 -1
- package/dist/{types-CMYee6LB.d.cts → scope-BC3djHz7.d.cts} +83 -8
- package/dist/{types-CXeWWYm6.d.ts → scope-CTxSo201.d.ts} +83 -8
- package/dist/scope.d.cts +1 -70
- package/dist/scope.d.ts +1 -70
- package/dist/{signal-BOAyevht.d.cts → signal-DWrUYmvd.d.cts} +1 -1
- package/dist/{signal-BOAyevht.d.ts → signal-DWrUYmvd.d.ts} +1 -1
- package/dist/signal-component.d.cts +1 -1
- package/dist/signal-component.d.ts +1 -1
- package/dist/signal.cjs +7 -7
- package/dist/signal.cjs.map +1 -1
- package/dist/signal.d.cts +1 -1
- package/dist/signal.d.ts +1 -1
- package/dist/signal.mjs +7 -7
- package/dist/signal.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -50,13 +50,15 @@ declare class ReactiveEffect<T = unknown> {
|
|
|
50
50
|
allowRecurse?: boolean;
|
|
51
51
|
onStop?: () => void;
|
|
52
52
|
onTrack?: (event: {
|
|
53
|
+
effect: ReactiveEffect;
|
|
53
54
|
target: object;
|
|
54
|
-
key
|
|
55
|
+
key?: string | symbol;
|
|
55
56
|
type: string;
|
|
56
57
|
}) => void;
|
|
57
58
|
onTrigger?: (event: {
|
|
59
|
+
effect: ReactiveEffect;
|
|
58
60
|
target: object;
|
|
59
|
-
key
|
|
61
|
+
key?: string | symbol;
|
|
60
62
|
type: string;
|
|
61
63
|
newValue?: unknown;
|
|
62
64
|
oldValue?: unknown;
|
|
@@ -89,13 +91,15 @@ declare function effect(fn: () => void, options?: {
|
|
|
89
91
|
allowRecurse?: boolean;
|
|
90
92
|
onStop?: () => void;
|
|
91
93
|
onTrack?: (event: {
|
|
94
|
+
effect: ReactiveEffect;
|
|
92
95
|
target: object;
|
|
93
|
-
key
|
|
96
|
+
key?: string | symbol;
|
|
94
97
|
type: string;
|
|
95
98
|
}) => void;
|
|
96
99
|
onTrigger?: (event: {
|
|
100
|
+
effect: ReactiveEffect;
|
|
97
101
|
target: object;
|
|
98
|
-
key
|
|
102
|
+
key?: string | symbol;
|
|
99
103
|
type: string;
|
|
100
104
|
newValue?: unknown;
|
|
101
105
|
oldValue?: unknown;
|
|
@@ -107,13 +111,15 @@ declare function effect<T>(fn: () => T, options: {
|
|
|
107
111
|
allowRecurse?: boolean;
|
|
108
112
|
onStop?: () => void;
|
|
109
113
|
onTrack?: (event: {
|
|
114
|
+
effect: ReactiveEffect;
|
|
110
115
|
target: object;
|
|
111
|
-
key
|
|
116
|
+
key?: string | symbol;
|
|
112
117
|
type: string;
|
|
113
118
|
}) => void;
|
|
114
119
|
onTrigger?: (event: {
|
|
120
|
+
effect: ReactiveEffect;
|
|
115
121
|
target: object;
|
|
116
|
-
key
|
|
122
|
+
key?: string | symbol;
|
|
117
123
|
type: string;
|
|
118
124
|
newValue?: unknown;
|
|
119
125
|
oldValue?: unknown;
|
|
@@ -212,7 +218,9 @@ interface DebuggerEvent {
|
|
|
212
218
|
effect: ReactiveEffect;
|
|
213
219
|
target: object;
|
|
214
220
|
type: 'track' | 'trigger';
|
|
215
|
-
key
|
|
221
|
+
key?: string | symbol;
|
|
222
|
+
newValue?: unknown;
|
|
223
|
+
oldValue?: unknown;
|
|
216
224
|
}
|
|
217
225
|
interface WatchOptions<Immediate = boolean> {
|
|
218
226
|
immediate?: Immediate;
|
|
@@ -267,4 +275,71 @@ type ReactiveObject<T extends object = object> = {
|
|
|
267
275
|
__v_isReactive: true;
|
|
268
276
|
};
|
|
269
277
|
|
|
270
|
-
|
|
278
|
+
/**
|
|
279
|
+
* effectScope 收集的条目类型
|
|
280
|
+
* - ReactiveEffect: 响应式副作用
|
|
281
|
+
* - EffectScope: 嵌套的子 scope
|
|
282
|
+
*/
|
|
283
|
+
type EffectScopeEntry = ReactiveEffect | EffectScope;
|
|
284
|
+
|
|
285
|
+
interface EffectScope {
|
|
286
|
+
/** 当前 scope 是否活跃 */
|
|
287
|
+
active: boolean;
|
|
288
|
+
/** scope 收集的 effects */
|
|
289
|
+
effects: EffectScopeEntry[];
|
|
290
|
+
/** scope 注册的清理回调 */
|
|
291
|
+
cleanups: (() => void)[];
|
|
292
|
+
/** 父 scope(嵌套时自动关联) */
|
|
293
|
+
parent: EffectScope | undefined;
|
|
294
|
+
/** 是否脱离父 scope(detached scope 不会被父 scope stop) */
|
|
295
|
+
detached: boolean;
|
|
296
|
+
/** 在 scope 上下文中执行 fn,期间创建的 effect 会被自动收集 */
|
|
297
|
+
run<T>(fn: () => T): T | undefined;
|
|
298
|
+
/** 停止 scope,清理所有收集的 effects 和 cleanups */
|
|
299
|
+
stop(): void;
|
|
300
|
+
}
|
|
301
|
+
interface EffectScopeOptions {
|
|
302
|
+
detached?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 创建一个 effect scope,用于批量管理响应式副作用。
|
|
306
|
+
*
|
|
307
|
+
* @param options - 配置选项。支持传入 boolean(兼容旧 API)或 EffectScopeOptions 对象。
|
|
308
|
+
* @returns EffectScope 实例
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const scope = effectScope()
|
|
313
|
+
* scope.run(() => {
|
|
314
|
+
* const count = ref(0)
|
|
315
|
+
* watch(count, () => console.log(count.value))
|
|
316
|
+
* })
|
|
317
|
+
* // 不再需要时一次性停止所有副作用
|
|
318
|
+
* scope.stop()
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
declare function effectScope(options?: boolean | EffectScopeOptions): EffectScope;
|
|
322
|
+
/**
|
|
323
|
+
* 获取当前活跃的 effectScope。
|
|
324
|
+
*/
|
|
325
|
+
declare function getCurrentScope(): EffectScope | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* 在当前活跃的 effectScope 中注册一个清理回调。
|
|
328
|
+
* 当 scope 被 stop 时,所有注册的回调会被执行。
|
|
329
|
+
*
|
|
330
|
+
* @param fn - 清理回调函数
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* const scope = effectScope()
|
|
335
|
+
* scope.run(() => {
|
|
336
|
+
* onScopeDispose(() => {
|
|
337
|
+
* console.log('scope disposed')
|
|
338
|
+
* })
|
|
339
|
+
* })
|
|
340
|
+
* scope.stop() // 输出: scope disposed
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
declare function onScopeDispose(fn: () => void): void;
|
|
344
|
+
|
|
345
|
+
export { stop as A, untrack as B, type ComputedGetter as C, type DebuggerEvent as D, type EffectScope as E, withFirstRenderOptimization as F, type OnCleanup as O, type ReactiveEffectOptions as R, type ToRefs as T, type UnwrapNestedRefs as U, type WatchCallback as W, type ComputedSetter as a, type DeepReadonly as b, type EffectScopeOptions as c, type ReactiveEffectRunner as d, type ReactiveObject as e, type UnwrapRef as f, type WatchCallbackWithImmediate as g, type WatchEffectOptions as h, type WatchHandle as i, type WatchOptions as j, type WatchSource as k, type WritableComputedOptions as l, type WritableComputedRef as m, batch as n, batchAsync as o, effect as p, effectScope as q, enableTracking as r, getCurrentScope as s, getSkippedTrackingCount as t, onEffectCleanup as u, onScopeDispose as v, pauseTracking as w, resetSkippedTrackingCount as x, resetTracking as y, shouldSkipTracking as z };
|
|
@@ -50,13 +50,15 @@ declare class ReactiveEffect<T = unknown> {
|
|
|
50
50
|
allowRecurse?: boolean;
|
|
51
51
|
onStop?: () => void;
|
|
52
52
|
onTrack?: (event: {
|
|
53
|
+
effect: ReactiveEffect;
|
|
53
54
|
target: object;
|
|
54
|
-
key
|
|
55
|
+
key?: string | symbol;
|
|
55
56
|
type: string;
|
|
56
57
|
}) => void;
|
|
57
58
|
onTrigger?: (event: {
|
|
59
|
+
effect: ReactiveEffect;
|
|
58
60
|
target: object;
|
|
59
|
-
key
|
|
61
|
+
key?: string | symbol;
|
|
60
62
|
type: string;
|
|
61
63
|
newValue?: unknown;
|
|
62
64
|
oldValue?: unknown;
|
|
@@ -89,13 +91,15 @@ declare function effect(fn: () => void, options?: {
|
|
|
89
91
|
allowRecurse?: boolean;
|
|
90
92
|
onStop?: () => void;
|
|
91
93
|
onTrack?: (event: {
|
|
94
|
+
effect: ReactiveEffect;
|
|
92
95
|
target: object;
|
|
93
|
-
key
|
|
96
|
+
key?: string | symbol;
|
|
94
97
|
type: string;
|
|
95
98
|
}) => void;
|
|
96
99
|
onTrigger?: (event: {
|
|
100
|
+
effect: ReactiveEffect;
|
|
97
101
|
target: object;
|
|
98
|
-
key
|
|
102
|
+
key?: string | symbol;
|
|
99
103
|
type: string;
|
|
100
104
|
newValue?: unknown;
|
|
101
105
|
oldValue?: unknown;
|
|
@@ -107,13 +111,15 @@ declare function effect<T>(fn: () => T, options: {
|
|
|
107
111
|
allowRecurse?: boolean;
|
|
108
112
|
onStop?: () => void;
|
|
109
113
|
onTrack?: (event: {
|
|
114
|
+
effect: ReactiveEffect;
|
|
110
115
|
target: object;
|
|
111
|
-
key
|
|
116
|
+
key?: string | symbol;
|
|
112
117
|
type: string;
|
|
113
118
|
}) => void;
|
|
114
119
|
onTrigger?: (event: {
|
|
120
|
+
effect: ReactiveEffect;
|
|
115
121
|
target: object;
|
|
116
|
-
key
|
|
122
|
+
key?: string | symbol;
|
|
117
123
|
type: string;
|
|
118
124
|
newValue?: unknown;
|
|
119
125
|
oldValue?: unknown;
|
|
@@ -212,7 +218,9 @@ interface DebuggerEvent {
|
|
|
212
218
|
effect: ReactiveEffect;
|
|
213
219
|
target: object;
|
|
214
220
|
type: 'track' | 'trigger';
|
|
215
|
-
key
|
|
221
|
+
key?: string | symbol;
|
|
222
|
+
newValue?: unknown;
|
|
223
|
+
oldValue?: unknown;
|
|
216
224
|
}
|
|
217
225
|
interface WatchOptions<Immediate = boolean> {
|
|
218
226
|
immediate?: Immediate;
|
|
@@ -267,4 +275,71 @@ type ReactiveObject<T extends object = object> = {
|
|
|
267
275
|
__v_isReactive: true;
|
|
268
276
|
};
|
|
269
277
|
|
|
270
|
-
|
|
278
|
+
/**
|
|
279
|
+
* effectScope 收集的条目类型
|
|
280
|
+
* - ReactiveEffect: 响应式副作用
|
|
281
|
+
* - EffectScope: 嵌套的子 scope
|
|
282
|
+
*/
|
|
283
|
+
type EffectScopeEntry = ReactiveEffect | EffectScope;
|
|
284
|
+
|
|
285
|
+
interface EffectScope {
|
|
286
|
+
/** 当前 scope 是否活跃 */
|
|
287
|
+
active: boolean;
|
|
288
|
+
/** scope 收集的 effects */
|
|
289
|
+
effects: EffectScopeEntry[];
|
|
290
|
+
/** scope 注册的清理回调 */
|
|
291
|
+
cleanups: (() => void)[];
|
|
292
|
+
/** 父 scope(嵌套时自动关联) */
|
|
293
|
+
parent: EffectScope | undefined;
|
|
294
|
+
/** 是否脱离父 scope(detached scope 不会被父 scope stop) */
|
|
295
|
+
detached: boolean;
|
|
296
|
+
/** 在 scope 上下文中执行 fn,期间创建的 effect 会被自动收集 */
|
|
297
|
+
run<T>(fn: () => T): T | undefined;
|
|
298
|
+
/** 停止 scope,清理所有收集的 effects 和 cleanups */
|
|
299
|
+
stop(): void;
|
|
300
|
+
}
|
|
301
|
+
interface EffectScopeOptions {
|
|
302
|
+
detached?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 创建一个 effect scope,用于批量管理响应式副作用。
|
|
306
|
+
*
|
|
307
|
+
* @param options - 配置选项。支持传入 boolean(兼容旧 API)或 EffectScopeOptions 对象。
|
|
308
|
+
* @returns EffectScope 实例
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const scope = effectScope()
|
|
313
|
+
* scope.run(() => {
|
|
314
|
+
* const count = ref(0)
|
|
315
|
+
* watch(count, () => console.log(count.value))
|
|
316
|
+
* })
|
|
317
|
+
* // 不再需要时一次性停止所有副作用
|
|
318
|
+
* scope.stop()
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
declare function effectScope(options?: boolean | EffectScopeOptions): EffectScope;
|
|
322
|
+
/**
|
|
323
|
+
* 获取当前活跃的 effectScope。
|
|
324
|
+
*/
|
|
325
|
+
declare function getCurrentScope(): EffectScope | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* 在当前活跃的 effectScope 中注册一个清理回调。
|
|
328
|
+
* 当 scope 被 stop 时,所有注册的回调会被执行。
|
|
329
|
+
*
|
|
330
|
+
* @param fn - 清理回调函数
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* const scope = effectScope()
|
|
335
|
+
* scope.run(() => {
|
|
336
|
+
* onScopeDispose(() => {
|
|
337
|
+
* console.log('scope disposed')
|
|
338
|
+
* })
|
|
339
|
+
* })
|
|
340
|
+
* scope.stop() // 输出: scope disposed
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
declare function onScopeDispose(fn: () => void): void;
|
|
344
|
+
|
|
345
|
+
export { stop as A, untrack as B, type ComputedGetter as C, type DebuggerEvent as D, type EffectScope as E, withFirstRenderOptimization as F, type OnCleanup as O, type ReactiveEffectOptions as R, type ToRefs as T, type UnwrapNestedRefs as U, type WatchCallback as W, type ComputedSetter as a, type DeepReadonly as b, type EffectScopeOptions as c, type ReactiveEffectRunner as d, type ReactiveObject as e, type UnwrapRef as f, type WatchCallbackWithImmediate as g, type WatchEffectOptions as h, type WatchHandle as i, type WatchOptions as j, type WatchSource as k, type WritableComputedOptions as l, type WritableComputedRef as m, batch as n, batchAsync as o, effect as p, effectScope as q, enableTracking as r, getCurrentScope as s, getSkippedTrackingCount as t, onEffectCleanup as u, onScopeDispose as v, pauseTracking as w, resetSkippedTrackingCount as x, resetTracking as y, shouldSkipTracking as z };
|
package/dist/scope.d.cts
CHANGED
|
@@ -1,71 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { E as EffectScope, c as EffectScopeOptions, q as effectScope, s as getCurrentScope, v as onScopeDispose } from './scope-BC3djHz7.cjs';
|
|
2
2
|
import './ref-CwOCKoy2.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* effectScope 收集的条目类型
|
|
6
|
-
* - ReactiveEffect: 响应式副作用
|
|
7
|
-
* - EffectScope: 嵌套的子 scope
|
|
8
|
-
*/
|
|
9
|
-
type EffectScopeEntry = ReactiveEffect | EffectScope;
|
|
10
|
-
|
|
11
|
-
interface EffectScope {
|
|
12
|
-
/** 当前 scope 是否活跃 */
|
|
13
|
-
active: boolean;
|
|
14
|
-
/** scope 收集的 effects */
|
|
15
|
-
effects: EffectScopeEntry[];
|
|
16
|
-
/** scope 注册的清理回调 */
|
|
17
|
-
cleanups: (() => void)[];
|
|
18
|
-
/** 父 scope(嵌套时自动关联) */
|
|
19
|
-
parent: EffectScope | undefined;
|
|
20
|
-
/** 是否脱离父 scope(detached scope 不会被父 scope stop) */
|
|
21
|
-
detached: boolean;
|
|
22
|
-
/** 在 scope 上下文中执行 fn,期间创建的 effect 会被自动收集 */
|
|
23
|
-
run<T>(fn: () => T): T | undefined;
|
|
24
|
-
/** 停止 scope,清理所有收集的 effects 和 cleanups */
|
|
25
|
-
stop(): void;
|
|
26
|
-
}
|
|
27
|
-
interface EffectScopeOptions {
|
|
28
|
-
detached?: boolean;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 创建一个 effect scope,用于批量管理响应式副作用。
|
|
32
|
-
*
|
|
33
|
-
* @param options - 配置选项。支持传入 boolean(兼容旧 API)或 EffectScopeOptions 对象。
|
|
34
|
-
* @returns EffectScope 实例
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const scope = effectScope()
|
|
39
|
-
* scope.run(() => {
|
|
40
|
-
* const count = ref(0)
|
|
41
|
-
* watch(count, () => console.log(count.value))
|
|
42
|
-
* })
|
|
43
|
-
* // 不再需要时一次性停止所有副作用
|
|
44
|
-
* scope.stop()
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
declare function effectScope(options?: boolean | EffectScopeOptions): EffectScope;
|
|
48
|
-
/**
|
|
49
|
-
* 获取当前活跃的 effectScope。
|
|
50
|
-
*/
|
|
51
|
-
declare function getCurrentScope(): EffectScope | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* 在当前活跃的 effectScope 中注册一个清理回调。
|
|
54
|
-
* 当 scope 被 stop 时,所有注册的回调会被执行。
|
|
55
|
-
*
|
|
56
|
-
* @param fn - 清理回调函数
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* const scope = effectScope()
|
|
61
|
-
* scope.run(() => {
|
|
62
|
-
* onScopeDispose(() => {
|
|
63
|
-
* console.log('scope disposed')
|
|
64
|
-
* })
|
|
65
|
-
* })
|
|
66
|
-
* scope.stop() // 输出: scope disposed
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function onScopeDispose(fn: () => void): void;
|
|
70
|
-
|
|
71
|
-
export { type EffectScope, type EffectScopeOptions, effectScope, getCurrentScope, onScopeDispose };
|
package/dist/scope.d.ts
CHANGED
|
@@ -1,71 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { E as EffectScope, c as EffectScopeOptions, q as effectScope, s as getCurrentScope, v as onScopeDispose } from './scope-CTxSo201.js';
|
|
2
2
|
import './ref-CwOCKoy2.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* effectScope 收集的条目类型
|
|
6
|
-
* - ReactiveEffect: 响应式副作用
|
|
7
|
-
* - EffectScope: 嵌套的子 scope
|
|
8
|
-
*/
|
|
9
|
-
type EffectScopeEntry = ReactiveEffect | EffectScope;
|
|
10
|
-
|
|
11
|
-
interface EffectScope {
|
|
12
|
-
/** 当前 scope 是否活跃 */
|
|
13
|
-
active: boolean;
|
|
14
|
-
/** scope 收集的 effects */
|
|
15
|
-
effects: EffectScopeEntry[];
|
|
16
|
-
/** scope 注册的清理回调 */
|
|
17
|
-
cleanups: (() => void)[];
|
|
18
|
-
/** 父 scope(嵌套时自动关联) */
|
|
19
|
-
parent: EffectScope | undefined;
|
|
20
|
-
/** 是否脱离父 scope(detached scope 不会被父 scope stop) */
|
|
21
|
-
detached: boolean;
|
|
22
|
-
/** 在 scope 上下文中执行 fn,期间创建的 effect 会被自动收集 */
|
|
23
|
-
run<T>(fn: () => T): T | undefined;
|
|
24
|
-
/** 停止 scope,清理所有收集的 effects 和 cleanups */
|
|
25
|
-
stop(): void;
|
|
26
|
-
}
|
|
27
|
-
interface EffectScopeOptions {
|
|
28
|
-
detached?: boolean;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 创建一个 effect scope,用于批量管理响应式副作用。
|
|
32
|
-
*
|
|
33
|
-
* @param options - 配置选项。支持传入 boolean(兼容旧 API)或 EffectScopeOptions 对象。
|
|
34
|
-
* @returns EffectScope 实例
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const scope = effectScope()
|
|
39
|
-
* scope.run(() => {
|
|
40
|
-
* const count = ref(0)
|
|
41
|
-
* watch(count, () => console.log(count.value))
|
|
42
|
-
* })
|
|
43
|
-
* // 不再需要时一次性停止所有副作用
|
|
44
|
-
* scope.stop()
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
declare function effectScope(options?: boolean | EffectScopeOptions): EffectScope;
|
|
48
|
-
/**
|
|
49
|
-
* 获取当前活跃的 effectScope。
|
|
50
|
-
*/
|
|
51
|
-
declare function getCurrentScope(): EffectScope | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* 在当前活跃的 effectScope 中注册一个清理回调。
|
|
54
|
-
* 当 scope 被 stop 时,所有注册的回调会被执行。
|
|
55
|
-
*
|
|
56
|
-
* @param fn - 清理回调函数
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* const scope = effectScope()
|
|
61
|
-
* scope.run(() => {
|
|
62
|
-
* onScopeDispose(() => {
|
|
63
|
-
* console.log('scope disposed')
|
|
64
|
-
* })
|
|
65
|
-
* })
|
|
66
|
-
* scope.stop() // 输出: scope disposed
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function onScopeDispose(fn: () => void): void;
|
|
70
|
-
|
|
71
|
-
export { type EffectScope, type EffectScopeOptions, effectScope, getCurrentScope, onScopeDispose };
|
|
@@ -106,4 +106,4 @@ declare function _getPendingNotificationsCount(): number;
|
|
|
106
106
|
/** @internal 重置全局状态(仅用于测试) */
|
|
107
107
|
declare function _resetSignalGlobalState(): void;
|
|
108
108
|
|
|
109
|
-
export { ComputedRefSymbol as C, ReactiveSymbol as R, ShallowRefSymbol as S, type WritableComputedSignal as W, _getActiveSubscriber as _, type ComputedSignal as a, type ReadonlySignal as b, ReadonlySymbol as c, RefSymbol as d, type Signal as e, type Subscriber as f, type WritableSignal as g,
|
|
109
|
+
export { ComputedRefSymbol as C, ReactiveSymbol as R, ShallowRefSymbol as S, type WritableComputedSignal as W, _getActiveSubscriber as _, type ComputedSignal as a, type ReadonlySignal as b, ReadonlySymbol as c, RefSymbol as d, type Signal as e, type Subscriber as f, type WritableSignal as g, _getBatchDepth as h, _getPendingNotificationsCount as i, _isSignalUntracked as j, _resetSignalGlobalState as k, computed as l, computedSignal as m, signal as n, signalBatch as o, signalUntrack as p, readonlySignal as r, set as s, update as u, valueOf as v, writableComputedSignal as w };
|
|
@@ -106,4 +106,4 @@ declare function _getPendingNotificationsCount(): number;
|
|
|
106
106
|
/** @internal 重置全局状态(仅用于测试) */
|
|
107
107
|
declare function _resetSignalGlobalState(): void;
|
|
108
108
|
|
|
109
|
-
export { ComputedRefSymbol as C, ReactiveSymbol as R, ShallowRefSymbol as S, type WritableComputedSignal as W, _getActiveSubscriber as _, type ComputedSignal as a, type ReadonlySignal as b, ReadonlySymbol as c, RefSymbol as d, type Signal as e, type Subscriber as f, type WritableSignal as g,
|
|
109
|
+
export { ComputedRefSymbol as C, ReactiveSymbol as R, ShallowRefSymbol as S, type WritableComputedSignal as W, _getActiveSubscriber as _, type ComputedSignal as a, type ReadonlySignal as b, ReadonlySymbol as c, RefSymbol as d, type Signal as e, type Subscriber as f, type WritableSignal as g, _getBatchDepth as h, _getPendingNotificationsCount as i, _isSignalUntracked as j, _resetSignalGlobalState as k, computed as l, computedSignal as m, signal as n, signalBatch as o, signalUntrack as p, readonlySignal as r, set as s, update as u, valueOf as v, writableComputedSignal as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as Signal, a as ComputedSignal, g as WritableSignal } from './signal-
|
|
1
|
+
import { e as Signal, a as ComputedSignal, g as WritableSignal } from './signal-DWrUYmvd.cjs';
|
|
2
2
|
|
|
3
3
|
interface SignalComponentOptions<T = Record<string, unknown>> {
|
|
4
4
|
signals?: {
|
package/dist/signal.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var TriggerOpTypes = {
|
|
|
15
15
|
var activeEffect;
|
|
16
16
|
var targetMap = /* @__PURE__ */ new WeakMap();
|
|
17
17
|
var triggerDepth = 0;
|
|
18
|
-
function trigger(target, type, key,
|
|
18
|
+
function trigger(target, type, key, newValue, oldValue) {
|
|
19
19
|
const depsMap = targetMap.get(target);
|
|
20
20
|
if (!depsMap) return;
|
|
21
21
|
const deps = [];
|
|
@@ -37,9 +37,9 @@ function trigger(target, type, key, _newValue, _oldValue) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
triggerEffects([...new Set(effects)]);
|
|
40
|
+
triggerEffects([...new Set(effects)], target, type, key, newValue, oldValue);
|
|
41
41
|
}
|
|
42
|
-
function triggerEffects(effects) {
|
|
42
|
+
function triggerEffects(effects, target, type, key, newValue, oldValue) {
|
|
43
43
|
if (triggerDepth > commonConstants.REACTIVITY_MAX_TRIGGER_DEPTH) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
@@ -47,19 +47,19 @@ function triggerEffects(effects) {
|
|
|
47
47
|
try {
|
|
48
48
|
for (const effect of effects) {
|
|
49
49
|
if (effect.computed) {
|
|
50
|
-
triggerEffect(effect);
|
|
50
|
+
triggerEffect(effect, target, type, key, newValue, oldValue);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
for (const effect of effects) {
|
|
54
54
|
if (!effect.computed) {
|
|
55
|
-
triggerEffect(effect);
|
|
55
|
+
triggerEffect(effect, target, type, key, newValue, oldValue);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
} finally {
|
|
59
59
|
triggerDepth--;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
function triggerEffect(effect) {
|
|
62
|
+
function triggerEffect(effect, target, type, key, newValue, oldValue) {
|
|
63
63
|
if (effect !== activeEffect || effect.allowRecurse) {
|
|
64
64
|
if (effect.scheduler) {
|
|
65
65
|
effect.scheduler();
|
|
@@ -257,7 +257,7 @@ function notifySubscribers(subscribers, store, signalKey, newValue) {
|
|
|
257
257
|
next = it.next();
|
|
258
258
|
}
|
|
259
259
|
if (store && signalKey !== void 0) {
|
|
260
|
-
trigger(store, TriggerOpTypes.SET, signalKey);
|
|
260
|
+
trigger(store, TriggerOpTypes.SET, signalKey, newValue);
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
function flushPendingNotifications() {
|