Skip to content

Commit b845df7

Browse files
committed
feat: add effectScope factory function
1 parent 72f05a3 commit b845df7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class EffectScope {
99
effects: (ReactiveEffect | EffectScope)[] = []
1010
cleanups: (() => void)[] = []
1111

12-
constructor(detached?: boolean) {
12+
constructor(detached = false) {
1313
if (!detached) {
1414
recordEffectScope(this)
1515
}
@@ -39,6 +39,10 @@ export class EffectScope {
3939
}
4040
}
4141

42+
export function effectScope(detached?: boolean) {
43+
return new EffectScope(detached)
44+
}
45+
4246
export function recordEffectScope(
4347
effect: ReactiveEffect | EffectScope,
4448
scope?: EffectScope | null

packages/reactivity/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ export {
5151
EffectScheduler,
5252
DebuggerEvent
5353
} from './effect'
54-
export { EffectScope, getCurrentScope, onScopeDispose } from './effectScope'
54+
export {
55+
effectScope,
56+
EffectScope,
57+
getCurrentScope,
58+
onScopeDispose
59+
} from './effectScope'
5560
export { TrackOpTypes, TriggerOpTypes } from './operations'

packages/runtime-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export {
2929
stop,
3030
ReactiveEffect,
3131
// effect scope
32+
effectScope,
3233
EffectScope,
3334
getCurrentScope,
3435
onScopeDispose

0 commit comments

Comments
 (0)