Skip to content

Commit

Permalink
refactor: add parent param to EffectScope constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed May 19, 2024
1 parent ac49e7f commit d387242
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
14 changes: 7 additions & 7 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class EffectScope {
*/
private index: number | undefined

constructor(public detached = false) {
this.parent = activeEffectScope
if (!detached && activeEffectScope) {
this.index =
(activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
this,
) - 1
constructor(
public detached = false,
parent = activeEffectScope,
) {
this.parent = parent
if (!detached && parent) {
this.index = (parent.scopes || (parent.scopes = [])).push(this) - 1
}
}

Expand Down
8 changes: 2 additions & 6 deletions packages/runtime-vapor/src/blockEffectScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EffectScope, getCurrentScope } from '@vue/reactivity'
import { EffectScope } from '@vue/reactivity'
import type { ComponentInternalInstance } from './component'
import type { DirectiveBindingsMap } from './directives'

Expand All @@ -23,11 +23,7 @@ export class BlockEffectScope extends EffectScope {
instance: ComponentInternalInstance,
parentScope: EffectScope | null,
) {
const isInOtherScope = parentScope && parentScope !== getCurrentScope()
// TODO refactor: add parent param to `EffectScope` constructor
isInOtherScope && parentScope.on()
super(!parentScope)
isInOtherScope && parentScope.off()
super(false, parentScope || undefined)
this.im = false
this.it = instance
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export function createComponentInstance(
*/
// [VaporLifecycleHooks.SERVER_PREFETCH]: null,
}
instance.scope = new BlockEffectScope(instance, parent ? parent.scope : null)
instance.scope = new BlockEffectScope(instance, parent && parent.scope)
initProps(instance, rawProps, !isFunction(component), once)
initSlots(instance, slots, dynamicSlots)
instance.emit = emit.bind(null, instance)
Expand Down

0 comments on commit d387242

Please sign in to comment.