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

55 lines
1.1 KiB
TypeScript
Raw Normal View History

export {
ref,
isRef,
2019-08-20 21:38:00 +08:00
toRefs,
reactive,
isReactive,
2019-08-23 21:38:32 +08:00
readonly,
isReadonly,
toRaw,
2019-08-23 21:38:32 +08:00
markReadonly,
markNonReactive,
effect,
// types
ReactiveEffect,
ReactiveEffectOptions,
DebuggerEvent,
TrackOpTypes,
TriggerOpTypes,
Ref,
ComputedRef,
2019-09-04 10:25:38 +08:00
UnwrapRef,
WritableComputedOptions
} from '@vue/reactivity'
import {
computed as _computed,
ComputedRef,
WritableComputedOptions,
ReactiveEffect,
2019-10-22 01:57:20 +08:00
WritableComputedRef,
ComputedGetter
} 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)
}
}
2019-10-22 01:57:20 +08:00
export function computed<T>(getter: ComputedGetter<T>): ComputedRef<T>
export function computed<T>(
options: WritableComputedOptions<T>
): WritableComputedRef<T>
export function computed<T>(
2019-10-22 01:57:20 +08:00
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>
) {
const c = _computed(getterOrOptions as any)
recordEffect(c.effect)
return c
}