Skip to content

Commit 48b47a1

Browse files
authoredOct 31, 2023
feat(reactivity): expose last result for computed getter (#9497)
1 parent 3c828f3 commit 48b47a1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎packages/reactivity/src/computed.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface WritableComputedRef<T> extends Ref<T> {
1616
readonly effect: ReactiveEffect<T>
1717
}
1818

19-
export type ComputedGetter<T> = (...args: any[]) => T
20-
export type ComputedSetter<T> = (v: T) => void
19+
export type ComputedGetter<T> = (oldValue?: T) => T
20+
export type ComputedSetter<T> = (newValue: T) => void
2121

2222
export interface WritableComputedOptions<T> {
2323
get: ComputedGetter<T>
@@ -41,9 +41,10 @@ export class ComputedRefImpl<T> {
4141
isReadonly: boolean,
4242
isSSR: boolean
4343
) {
44-
this.effect = new ReactiveEffect(getter, () => {
45-
triggerRefValue(this, DirtyLevels.ComputedValueMaybeDirty)
46-
})
44+
this.effect = new ReactiveEffect(
45+
() => getter(this._value),
46+
() => triggerRefValue(this, DirtyLevels.ComputedValueMaybeDirty)
47+
)
4748
this.effect.computed = this
4849
this.effect.active = this._cacheable = !isSSR
4950
this[ReactiveFlags.IS_READONLY] = isReadonly

0 commit comments

Comments
 (0)
Please sign in to comment.