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