Skip to content

Commit

Permalink
feat(reactivity): expose last result for computed getter (#9497)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored Oct 31, 2023
1 parent 3c828f3 commit 48b47a1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down

0 comments on commit 48b47a1

Please sign in to comment.