diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index fddb2e0d498..f3054648b0c 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -4,7 +4,6 @@ import { type DebuggerOptions, EffectFlags, type Link, - type ReactiveEffect, type Subscriber, activeSub, refreshComputed, @@ -25,7 +24,7 @@ export interface WritableComputedRef extends Ref { /** * @deprecated computed no longer uses effect */ - effect: ReactiveEffect + effect: ComputedRefImpl } export type ComputedGetter = (oldValue?: T) => T @@ -41,18 +40,43 @@ export interface WritableComputedOptions { * the main vue package */ export class ComputedRefImpl implements Subscriber { - // A computed is a ref + /** + * @internal + */ _value: any = undefined + /** + * @internal + */ readonly dep = new Dep(this) + /** + * @internal + */ readonly __v_isRef = true; + /** + * @internal + */ readonly [ReactiveFlags.IS_READONLY]: boolean // A computed is also a subscriber that tracks other deps + /** + * @internal + */ deps?: Link = undefined + /** + * @internal + */ depsTail?: Link = undefined - // track variaous states + /** + * @internal + */ flags = EffectFlags.DIRTY - // last seen global version + /** + * @internal + */ globalVersion = globalVersion - 1 + /** + * @internal + */ + isSSR: boolean // for backwards compat effect = this @@ -63,17 +87,22 @@ export class ComputedRefImpl implements Subscriber { /** * Dev only + * @internal */ _warnRecursive?: boolean constructor( public fn: ComputedGetter, private readonly setter: ComputedSetter | undefined, - public isSSR: boolean, + isSSR: boolean, ) { this.__v_isReadonly = !setter + this.isSSR = isSSR } + /** + * @internal + */ notify() { // avoid infinite self recursion if (activeSub !== this) {