]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: Merge branch 'main' into minor
authorEvan You <yyx990803@gmail.com>
Mon, 26 Feb 2024 02:13:44 +0000 (10:13 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 26 Feb 2024 02:13:44 +0000 (10:13 +0800)
1  2 
packages/reactivity/__tests__/gc.spec.ts
packages/reactivity/src/baseHandlers.ts
packages/reactivity/src/collectionHandlers.ts
packages/reactivity/src/computed.ts
packages/reactivity/src/index.ts
packages/reactivity/src/ref.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/components/BaseTransition.ts

index 2636287b6106269462c37d2dc2f740aae3ee3324,2b7785ae7ebc56d26d65efc847d38d99abf2c44b..6f1dbd3e563d1febe2ae665cd23c2c9640daaafc
@@@ -1,7 -1,13 +1,8 @@@
  import { toRaw, toReactive, toReadonly } from './reactive'
 -import {
 -  ITERATE_KEY,
 -  MAP_KEY_ITERATE_KEY,
 -  track,
 -  trigger,
 -} from './reactiveEffect'
 +import { ITERATE_KEY, MAP_KEY_ITERATE_KEY, track, trigger } from './dep'
  import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
  import { capitalize, hasChanged, hasOwn, isMap, toRawType } from '@vue/shared'
+ import { warn } from './warning'
  
  type CollectionTypes = IterableCollections | WeakCollections
  
index 3e0fce6ec0209841344a403edc3627f884bbfd65,da63fe84750af13db7bdb7c8d9968e65b8b9cbe0..a3c6de407aa974becdcb3390eabb5441e133e42e
@@@ -36,71 -25,81 +36,76 @@@ export interface WritableComputedOption
    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 = undefined
 -
 -  private _value!: T
 -  public readonly effect: ReactiveEffect<T>
 -
 -  public readonly __v_isRef = true
 -  public readonly [ReactiveFlags.IS_READONLY]: boolean = false
 -
 -  public _cacheable: boolean
 +/**
 + * @internal
 + */
 +export class ComputedRefImpl<T = any> implements Subscriber {
 +  // A computed is a ref
 +  _value: any = undefined
 +  readonly dep = new Dep(this)
 +  readonly __v_isRef = true;
 +  readonly [ReactiveFlags.IS_READONLY]: boolean
 +  // A computed is also a subscriber that tracks other deps
 +  deps?: Link = undefined
 +  depsTail?: Link = undefined
 +  // track variaous states
 +  flags = EffectFlags.DIRTY
 +  // last seen global version
 +  globalVersion = globalVersion - 1
 +  // for backwards compat
 +  effect = this
 +
 +  // dev only
 +  onTrack?: (event: DebuggerEvent) => void
 +  // dev only
 +  onTrigger?: (event: DebuggerEvent) => void
  
+   /**
+    * Dev only
+    */
+   _warnRecursive?: boolean
    constructor(
 -    private getter: ComputedGetter<T>,
 -    private readonly _setter: ComputedSetter<T>,
 -    isReadonly: boolean,
 -    isSSR: boolean,
 +    public fn: ComputedGetter<T>,
 +    private readonly setter: ComputedSetter<T> | undefined,
 +    public isSSR: boolean,
    ) {
 -    this.effect = new ReactiveEffect(
 -      () => getter(this._value),
 -      () =>
 -        triggerRefValue(
 -          this,
 -          this.effect._dirtyLevel === DirtyLevels.MaybeDirty_ComputedSideEffect
 -            ? DirtyLevels.MaybeDirty_ComputedSideEffect
 -            : DirtyLevels.MaybeDirty,
 -        ),
 -    )
 -    this.effect.computed = this
 -    this.effect.active = this._cacheable = !isSSR
 -    this[ReactiveFlags.IS_READONLY] = isReadonly
 +    this.__v_isReadonly = !setter
    }
  
 -  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) &&
 -      hasChanged(self._value, (self._value = self.effect.run()!))
 -    ) {
 -      triggerRefValue(self, DirtyLevels.Dirty)
 -    }
 -    trackRefValue(self)
 -    if (self.effect._dirtyLevel >= DirtyLevels.MaybeDirty_ComputedSideEffect) {
 -      if (__DEV__ && (__TEST__ || this._warnRecursive)) {
 -        warn(COMPUTED_SIDE_EFFECT_WARN, `\n\ngetter: `, this.getter)
 -      }
 -      triggerRefValue(self, DirtyLevels.MaybeDirty_ComputedSideEffect)
 +  notify() {
 +    // avoid infinite self recursion
 +    if (activeSub !== this) {
 +      this.flags |= EffectFlags.DIRTY
 +      this.dep.notify()
 +    } else if (__DEV__) {
 +      // TODO warn
      }
 -    return self._value
 -  }
 -
 -  set value(newValue: T) {
 -    this._setter(newValue)
    }
  
 -  // #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
 -  get _dirty() {
 -    return this.effect.dirty
 +  get value() {
 +    const link = __DEV__
 +      ? this.dep.track({
 +          target: this,
 +          type: TrackOpTypes.GET,
 +          key: 'value',
 +        })
 +      : this.dep.track()
 +    refreshComputed(this)
 +    // sync version after evaluation
 +    if (link) {
 +      link.version = this.dep.version
 +    }
 +    return this._value
    }
  
 -  set _dirty(v) {
 -    this.effect.dirty = v
 +  set value(newValue) {
 +    if (this.setter) {
 +      this.setter(newValue)
 +    } else if (__DEV__) {
 +      warn('Write operation failed: computed value is readonly')
 +    }
    }
 -  // #endregion
  }
  
  /**
index 40bdf7b1b0485f0703dbfa9d96f8c4d6bc4ecd5e,505ec9e2035939e4d6704c7b647d1086546d7f53..1b85e47b36f707cd5224cc6f865e254df4fbce34
@@@ -43,7 -43,9 +43,8 @@@ export 
    type WritableComputedOptions,
    type ComputedGetter,
    type ComputedSetter,
+   type ComputedRefImpl,
  } from './computed'
 -export { deferredComputed } from './deferredComputed'
  export {
    effect,
    stop,
index bfde3b787e3a0962e2b47572c0f2ee91eb3af825,5f40fbb7c286cd2380163f0422275c118091f678..32f79217e7bc0aeaa84101f8bea1035b29a57258
@@@ -15,8 -21,11 +15,9 @@@ 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 { TrackOpTypes, TriggerOpTypes } from './constants'
+ import { warn } from './warning'
  
  declare const RefSymbol: unique symbol
  export declare const RawSymbol: unique symbol