Skip to content

Commit

Permalink
feat: add effectScope factory function
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 6, 2021
1 parent 72f05a3 commit b845df7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class EffectScope {
effects: (ReactiveEffect | EffectScope)[] = []
cleanups: (() => void)[] = []

constructor(detached?: boolean) {
constructor(detached = false) {
if (!detached) {
recordEffectScope(this)
}
Expand Down Expand Up @@ -39,6 +39,10 @@ export class EffectScope {
}
}

export function effectScope(detached?: boolean) {
return new EffectScope(detached)
}

export function recordEffectScope(
effect: ReactiveEffect | EffectScope,
scope?: EffectScope | null
Expand Down
7 changes: 6 additions & 1 deletion packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ export {
EffectScheduler,
DebuggerEvent
} from './effect'
export { EffectScope, getCurrentScope, onScopeDispose } from './effectScope'
export {
effectScope,
EffectScope,
getCurrentScope,
onScopeDispose
} from './effectScope'
export { TrackOpTypes, TriggerOpTypes } from './operations'
1 change: 1 addition & 0 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {
stop,
ReactiveEffect,
// effect scope
effectScope,
EffectScope,
getCurrentScope,
onScopeDispose
Expand Down

0 comments on commit b845df7

Please sign in to comment.