wip: make computed implementation consistent
This commit is contained in:
@@ -23,11 +23,11 @@ export {
|
||||
import {
|
||||
computed as _computed,
|
||||
ComputedRef,
|
||||
ComputedOptions,
|
||||
ReactiveEffect
|
||||
} from '@vue/reactivity'
|
||||
|
||||
import { currentInstance } from './component'
|
||||
import { isFunction } from '@vue/shared'
|
||||
|
||||
// record effects created during a component's setup() so that they can be
|
||||
// stopped when the component unmounts
|
||||
@@ -37,20 +37,10 @@ export function recordEffect(effect: ReactiveEffect) {
|
||||
}
|
||||
}
|
||||
|
||||
interface ComputedOptions<T> {
|
||||
get: () => T
|
||||
set: (v: T) => void
|
||||
}
|
||||
|
||||
export function computed<T>(
|
||||
getterOrOptions: (() => T) | ComputedOptions<T>
|
||||
): ComputedRef<T> {
|
||||
let c: ComputedRef<T>
|
||||
if (isFunction(getterOrOptions)) {
|
||||
c = _computed(getterOrOptions)
|
||||
} else {
|
||||
c = _computed(getterOrOptions.get, getterOrOptions.set)
|
||||
}
|
||||
const c = _computed(getterOrOptions)
|
||||
recordEffect(c.effect)
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user