feat(reactivity): expose last result for computed getter (#9497)

This commit is contained in:
Johnson Chu 2023-10-31 22:19:40 +08:00 committed by GitHub
parent 3c828f3cfb
commit 48b47a1ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -16,8 +16,8 @@ export interface WritableComputedRef<T> extends Ref<T> {
readonly effect: ReactiveEffect<T>
}
export type ComputedGetter<T> = (...args: any[]) => T
export type ComputedSetter<T> = (v: T) => void
export type ComputedGetter<T> = (oldValue?: T) => T
export type ComputedSetter<T> = (newValue: T) => void
export interface WritableComputedOptions<T> {
get: ComputedGetter<T>
@ -41,9 +41,10 @@ export class ComputedRefImpl<T> {
isReadonly: boolean,
isSSR: boolean
) {
this.effect = new ReactiveEffect(getter, () => {
triggerRefValue(this, DirtyLevels.ComputedValueMaybeDirty)
})
this.effect = new ReactiveEffect(
() => getter(this._value),
() => triggerRefValue(this, DirtyLevels.ComputedValueMaybeDirty)
)
this.effect.computed = this
this.effect.active = this._cacheable = !isSSR
this[ReactiveFlags.IS_READONLY] = isReadonly