Skip to content

Commit

Permalink
types: fix ComputedRefImpl type build
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 26, 2024
1 parent 5d30366 commit 72bde94
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type DebuggerOptions,
EffectFlags,
type Link,
type ReactiveEffect,
type Subscriber,
activeSub,
refreshComputed,
Expand All @@ -25,7 +24,7 @@ export interface WritableComputedRef<T> extends Ref<T> {
/**
* @deprecated computed no longer uses effect
*/
effect: ReactiveEffect
effect: ComputedRefImpl
}

export type ComputedGetter<T> = (oldValue?: T) => T
Expand All @@ -41,18 +40,43 @@ export interface WritableComputedOptions<T> {
* the main vue package
*/
export class ComputedRefImpl<T = any> 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

Expand All @@ -63,17 +87,22 @@ export class ComputedRefImpl<T = any> implements Subscriber {

/**
* Dev only
* @internal
*/
_warnRecursive?: boolean

constructor(
public fn: ComputedGetter<T>,
private readonly setter: ComputedSetter<T> | undefined,
public isSSR: boolean,
isSSR: boolean,
) {
this.__v_isReadonly = !setter
this.isSSR = isSSR
}

/**
* @internal
*/
notify() {
// avoid infinite self recursion
if (activeSub !== this) {
Expand Down

0 comments on commit 72bde94

Please sign in to comment.