Skip to content

Commit

Permalink
Try remove computed _cacheable property
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Feb 18, 2024
1 parent 272ab9f commit 6db7890
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
12 changes: 3 additions & 9 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ export class ComputedRefImpl<T> {
public readonly __v_isRef = true
public readonly [ReactiveFlags.IS_READONLY]: boolean = false

public _cacheable: boolean

constructor(
getter: ComputedGetter<T>,
private readonly _setter: ComputedSetter<T>,
isReadonly: boolean,
isSSR: boolean,
) {
this.effect = new ReactiveEffect(
() => getter(this._value),
Expand All @@ -58,16 +55,14 @@ export class ComputedRefImpl<T> {
: DirtyLevels.MaybeDirty,
),
)
this.effect.computed = this
this.effect.active = this._cacheable = !isSSR
this[ReactiveFlags.IS_READONLY] = isReadonly
}

get value() {
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
const self = toRaw(this)
if (
(!self._cacheable || self.effect.dirty) &&
self.effect.dirty &&
hasChanged(self._value, (self._value = self.effect.run()!))
) {
triggerRefValue(self, DirtyLevels.Dirty)
Expand Down Expand Up @@ -139,7 +134,6 @@ export function computed<T>(
export function computed<T>(
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>,
debugOptions?: DebuggerOptions,
isSSR = false,
) {
let getter: ComputedGetter<T>
let setter: ComputedSetter<T>
Expand All @@ -157,9 +151,9 @@ export function computed<T>(
setter = getterOrOptions.set
}

const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR)
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter)

if (__DEV__ && debugOptions && !isSSR) {
if (__DEV__ && debugOptions) {
cRef.effect.onTrack = debugOptions.onTrack
cRef.effect.onTrigger = debugOptions.onTrigger
}
Expand Down
5 changes: 0 additions & 5 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export class ReactiveEffect<T = any> {
active = true
deps: Dep[] = []

/**
* Can be attached after creation
* @internal
*/
computed?: ComputedRefImpl<T>
/**
* @internal
*/
Expand Down
9 changes: 0 additions & 9 deletions packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ function renderComponentSubTree(
comp.ssrRender = ssrCompile(comp.template, instance)
}

// perf: enable caching of computed getters during render
// since there cannot be state mutations during render.
for (const e of instance.scope.effects) {
if (e.computed) {
e.computed._dirty = true
e.computed._cacheable = true
}
}

const ssrRender = instance.ssrRender || comp.ssrRender
if (ssrRender) {
// optimized
Expand Down

0 comments on commit 6db7890

Please sign in to comment.