vue3-yuanma/packages/runtime-core/src/apiReactivity.ts

48 lines
992 B
TypeScript
Raw Normal View History

export {
ref,
isRef,
2019-08-20 21:38:00 +08:00
toRefs,
reactive,
isReactive,
immutable,
isImmutable,
toRaw,
markImmutable,
markNonReactive,
effect,
// types
ReactiveEffect,
ReactiveEffectOptions,
DebuggerEvent,
OperationTypes,
Ref,
ComputedRef,
UnwrapRef
} from '@vue/reactivity'
import {
Ref,
computed as _computed,
ComputedRef,
ComputedOptions,
ReactiveEffect
} from '@vue/reactivity'
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)
}
}
export function computed<T>(getter: () => T): ComputedRef<T>
export function computed<T>(options: ComputedOptions<T>): Ref<T>
export function computed<T>(getterOrOptions: any) {
const c = _computed(getterOrOptions)
recordEffect(c.effect)
return c
}