Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored and OnlyWick committed Mar 1, 2024
1 parent 687dc19 commit 42d6207
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
67 changes: 50 additions & 17 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type DebuggerOptions, ReactiveEffect } from './effect'
import { type Ref, trackRefValue, triggerRefValue } from './ref'
import { NOOP, hasChanged, isFunction } from '@vue/shared'
import { toRaw } from './reactive'
import type { Dep } from './dep'
import { Dep } from './dep'
import { DirtyLevels, ReactiveFlags } from './constants'
import { warn } from './warning'

Expand All @@ -25,22 +25,55 @@ export interface WritableComputedOptions<T> {
set: ComputedSetter<T>
}

export const COMPUTED_SIDE_EFFECT_WARN =
`Computed is still dirty after getter evaluation,` +
` likely because a computed is mutating its own dependency in its getter.` +
` State mutations in computed getters should be avoided. ` +
` Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`

export class ComputedRefImpl<T> {
public dep?: Dep

private _value!: T
public readonly effect: ReactiveEffect<T>

public readonly [ReactiveFlags.IS_REF] = true
public readonly [ReactiveFlags.IS_READONLY]: boolean = false

public _cacheable: boolean
/**
* @private exported by @vue/reactivity for Vue core use, but not exported from
* the main vue package
*/
export class ComputedRefImpl<T = any> implements Subscriber {
/**
* @internal
*/
_value: any = undefined
/**
* @internal
*/
readonly dep = new Dep(this);
/**
* @internal
*/
readonly [ReactiveFlags.IS_REF] = 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
/**
* @internal
*/
flags = EffectFlags.DIRTY
/**
* @internal
*/
globalVersion = globalVersion - 1
/**
* @internal
*/
isSSR: boolean
// for backwards compat
effect = this

// dev only
onTrack?: (event: DebuggerEvent) => void
// dev only
onTrigger?: (event: DebuggerEvent) => void

/**
* Dev only
Expand Down
16 changes: 4 additions & 12 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import type { ComputedRef } from './computed'
import {
activeEffect,
shouldTrack,
trackEffect,
triggerEffects,
} from './effect'
import {
DirtyLevels,
ReactiveFlags,
TrackOpTypes,
TriggerOpTypes,
} from './constants'
import {
type IfAny,
hasChanged,
Expand All @@ -26,10 +19,8 @@ import {
toRaw,
toReactive,
} from './reactive'
import type { ShallowReactiveMarker } from './reactive'
import { type Dep, createDep } from './dep'
import { ComputedRefImpl } from './computed'
import { getDepFromReactive } from './reactiveEffect'
import type { ComputedRef } from './computed'
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
import { warn } from './warning'

declare const RefSymbol: unique symbol
Expand Down Expand Up @@ -161,7 +152,8 @@ class RefImpl<T> {
private _value: T
private _rawValue: T

public dep?: Dep
dep: Dep = new Dep()

public readonly [ReactiveFlags.IS_REF] = true
public readonly [ReactiveFlags.IS_SHALLOW]: boolean = false

Expand Down

0 comments on commit 42d6207

Please sign in to comment.