2019-06-07 14:55:38 +08:00
|
|
|
export {
|
|
|
|
value,
|
|
|
|
isValue,
|
2019-06-11 23:50:28 +08:00
|
|
|
state,
|
|
|
|
isState,
|
|
|
|
immutableState,
|
|
|
|
isImmutableState,
|
|
|
|
toRaw,
|
2019-06-07 14:55:38 +08:00
|
|
|
markImmutable,
|
|
|
|
markNonReactive,
|
|
|
|
effect,
|
|
|
|
// types
|
|
|
|
ReactiveEffect,
|
|
|
|
ReactiveEffectOptions,
|
|
|
|
DebuggerEvent,
|
|
|
|
OperationTypes,
|
|
|
|
Value,
|
|
|
|
ComputedValue,
|
|
|
|
UnwrapValue
|
2019-06-11 23:50:28 +08:00
|
|
|
} from '@vue/reactivity'
|
2019-06-07 14:55:38 +08:00
|
|
|
|
|
|
|
import {
|
|
|
|
computed as _computed,
|
|
|
|
ComputedValue,
|
|
|
|
ReactiveEffect
|
2019-06-11 23:50:28 +08:00
|
|
|
} from '@vue/reactivity'
|
2019-06-07 14:55:38 +08:00
|
|
|
|
|
|
|
import { currentInstance } from './component'
|
|
|
|
|
|
|
|
// record effects created during a component's setup() so that they can be
|
|
|
|
// stopped when the component unmounts
|
|
|
|
export function recordEffect(effect: ReactiveEffect) {
|
|
|
|
if (currentInstance) {
|
|
|
|
;(currentInstance.effects || (currentInstance.effects = [])).push(effect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// a wrapped version of raw computed to tear it down at component unmount
|
|
|
|
export function computed<T, C = null>(
|
|
|
|
getter: () => T,
|
|
|
|
setter?: (v: T) => void
|
|
|
|
): ComputedValue<T> {
|
|
|
|
const c = _computed(getter, setter)
|
|
|
|
recordEffect(c.effect)
|
|
|
|
return c
|
|
|
|
}
|