]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(reactivity): expose last result for computed getter (#9497)
authorJohnson Chu <johnsoncodehk@gmail.com>
Tue, 31 Oct 2023 14:19:40 +0000 (22:19 +0800)
committerGitHub <noreply@github.com>
Tue, 31 Oct 2023 14:19:40 +0000 (22:19 +0800)
packages/reactivity/src/computed.ts

index 09247360d06e6b759cd7c7ba99972083a535f19d..c48e2f0df2c4983daefaf39d8a2ef3b1e4c37ae3 100644 (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