feat(reactivity): new effectScope API (#2195)

This commit is contained in:
Anthony Fu
2021-07-07 21:07:19 +08:00
committed by Evan You
parent 87f69fd0bb
commit f5617fc3bb
16 changed files with 400 additions and 89 deletions

View File

@@ -25,8 +25,7 @@ import {
import {
currentInstance,
ComponentInternalInstance,
isInSSRComponentSetup,
recordInstanceBoundEffect
isInSSRComponentSetup
} from './component'
import {
ErrorCodes,
@@ -326,15 +325,14 @@ function doWatch(
}
}
const effect = new ReactiveEffect(getter, scheduler)
const scope = instance && instance.scope
const effect = new ReactiveEffect(getter, scheduler, scope)
if (__DEV__) {
effect.onTrack = onTrack
effect.onTrigger = onTrigger
}
recordInstanceBoundEffect(effect, instance)
// initial run
if (cb) {
if (immediate) {
@@ -353,8 +351,8 @@ function doWatch(
return () => {
effect.stop()
if (instance) {
remove(instance.effects!, effect)
if (scope) {
remove(scope.effects!, effect)
}
}
}