refactor: remove isTracking() method
This commit is contained in:
parent
bb43704b64
commit
a51f935b72
@ -45,7 +45,7 @@ export type DebuggerEventExtraInfo = {
|
|||||||
oldTarget?: Map<any, any> | Set<any>
|
oldTarget?: Map<any, any> | Set<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
let activeEffect: ReactiveEffect | undefined
|
export let activeEffect: ReactiveEffect | undefined
|
||||||
|
|
||||||
export const ITERATE_KEY = Symbol(__DEV__ ? 'iterate' : '')
|
export const ITERATE_KEY = Symbol(__DEV__ ? 'iterate' : '')
|
||||||
export const MAP_KEY_ITERATE_KEY = Symbol(__DEV__ ? 'Map key iterate' : '')
|
export const MAP_KEY_ITERATE_KEY = Symbol(__DEV__ ? 'Map key iterate' : '')
|
||||||
@ -181,7 +181,7 @@ export function stop(runner: ReactiveEffectRunner) {
|
|||||||
runner.effect.stop()
|
runner.effect.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
let shouldTrack = true
|
export let shouldTrack = true
|
||||||
const trackStack: boolean[] = []
|
const trackStack: boolean[] = []
|
||||||
|
|
||||||
export function pauseTracking() {
|
export function pauseTracking() {
|
||||||
@ -200,27 +200,22 @@ export function resetTracking() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function track(target: object, type: TrackOpTypes, key: unknown) {
|
export function track(target: object, type: TrackOpTypes, key: unknown) {
|
||||||
if (!isTracking()) {
|
if (shouldTrack && activeEffect) {
|
||||||
return
|
let depsMap = targetMap.get(target)
|
||||||
}
|
if (!depsMap) {
|
||||||
let depsMap = targetMap.get(target)
|
targetMap.set(target, (depsMap = new Map()))
|
||||||
if (!depsMap) {
|
}
|
||||||
targetMap.set(target, (depsMap = new Map()))
|
let dep = depsMap.get(key)
|
||||||
}
|
if (!dep) {
|
||||||
let dep = depsMap.get(key)
|
depsMap.set(key, (dep = createDep()))
|
||||||
if (!dep) {
|
}
|
||||||
depsMap.set(key, (dep = createDep()))
|
|
||||||
}
|
|
||||||
|
|
||||||
const eventInfo = __DEV__
|
const eventInfo = __DEV__
|
||||||
? { effect: activeEffect, target, type, key }
|
? { effect: activeEffect, target, type, key }
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
trackEffects(dep, eventInfo)
|
trackEffects(dep, eventInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isTracking() {
|
|
||||||
return shouldTrack && !!activeEffect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackEffects(
|
export function trackEffects(
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import { isTracking, trackEffects, triggerEffects } from './effect'
|
import {
|
||||||
|
activeEffect,
|
||||||
|
shouldTrack,
|
||||||
|
trackEffects,
|
||||||
|
triggerEffects
|
||||||
|
} from './effect'
|
||||||
import { TrackOpTypes, TriggerOpTypes } from './operations'
|
import { TrackOpTypes, TriggerOpTypes } from './operations'
|
||||||
import { isArray, hasChanged, IfAny } from '@vue/shared'
|
import { isArray, hasChanged, IfAny } from '@vue/shared'
|
||||||
import { isProxy, toRaw, isReactive, toReactive } from './reactive'
|
import { isProxy, toRaw, isReactive, toReactive } from './reactive'
|
||||||
@ -24,19 +29,16 @@ type RefBase<T> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function trackRefValue(ref: RefBase<any>) {
|
export function trackRefValue(ref: RefBase<any>) {
|
||||||
if (isTracking()) {
|
if (shouldTrack && activeEffect) {
|
||||||
ref = toRaw(ref)
|
ref = toRaw(ref)
|
||||||
if (!ref.dep) {
|
|
||||||
ref.dep = createDep()
|
|
||||||
}
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
trackEffects(ref.dep, {
|
trackEffects(ref.dep || (ref.dep = createDep()), {
|
||||||
target: ref,
|
target: ref,
|
||||||
type: TrackOpTypes.GET,
|
type: TrackOpTypes.GET,
|
||||||
key: 'value'
|
key: 'value'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
trackEffects(ref.dep)
|
trackEffects(ref.dep || (ref.dep = createDep()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user