mirror of https://github.com/vuejs/core.git
chore(reactivity): change literal flag properties to enum flag properties (#10367)
This commit is contained in:
parent
189573dcee
commit
f8eba75d0a
|
@ -47,11 +47,11 @@ export class ComputedRefImpl<T = any> implements Subscriber {
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
readonly dep = new Dep(this)
|
readonly dep = new Dep(this);
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
readonly __v_isRef = true;
|
readonly [ReactiveFlags.IS_REF] = true;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -96,7 +96,7 @@ export class ComputedRefImpl<T = any> implements Subscriber {
|
||||||
private readonly setter: ComputedSetter<T> | undefined,
|
private readonly setter: ComputedSetter<T> | undefined,
|
||||||
isSSR: boolean,
|
isSSR: boolean,
|
||||||
) {
|
) {
|
||||||
this.__v_isReadonly = !setter
|
this[ReactiveFlags.IS_READONLY] = !setter
|
||||||
this.isSSR = isSSR
|
this.isSSR = isSSR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ export enum ReactiveFlags {
|
||||||
IS_READONLY = '__v_isReadonly',
|
IS_READONLY = '__v_isReadonly',
|
||||||
IS_SHALLOW = '__v_isShallow',
|
IS_SHALLOW = '__v_isShallow',
|
||||||
RAW = '__v_raw',
|
RAW = '__v_raw',
|
||||||
|
IS_REF = '__v_isRef',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DirtyLevels {
|
export enum DirtyLevels {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
toReactive,
|
toReactive,
|
||||||
} from './reactive'
|
} from './reactive'
|
||||||
import type { ComputedRef } from './computed'
|
import type { ComputedRef } from './computed'
|
||||||
import { TrackOpTypes, TriggerOpTypes } from './constants'
|
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
|
||||||
import { warn } from './warning'
|
import { warn } from './warning'
|
||||||
|
|
||||||
declare const RefSymbol: unique symbol
|
declare const RefSymbol: unique symbol
|
||||||
|
@ -40,7 +40,7 @@ export interface Ref<T = any> {
|
||||||
*/
|
*/
|
||||||
export function isRef<T>(r: Ref<T> | unknown): r is Ref<T>
|
export function isRef<T>(r: Ref<T> | unknown): r is Ref<T>
|
||||||
export function isRef(r: any): r is Ref {
|
export function isRef(r: any): r is Ref {
|
||||||
return r ? r.__v_isRef === true : false
|
return r ? r[ReactiveFlags.IS_REF] === true : false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,14 +105,13 @@ class RefImpl<T = any> {
|
||||||
|
|
||||||
dep: Dep = new Dep()
|
dep: Dep = new Dep()
|
||||||
|
|
||||||
public readonly __v_isRef = true
|
public readonly [ReactiveFlags.IS_REF] = true
|
||||||
|
public readonly [ReactiveFlags.IS_SHALLOW]: boolean = false
|
||||||
|
|
||||||
constructor(
|
constructor(value: T, isShallow: boolean) {
|
||||||
value: T,
|
this._rawValue = isShallow ? value : toRaw(value)
|
||||||
public readonly __v_isShallow: boolean,
|
this._value = isShallow ? value : toReactive(value)
|
||||||
) {
|
this[ReactiveFlags.IS_SHALLOW] = isShallow
|
||||||
this._rawValue = __v_isShallow ? value : toRaw(value)
|
|
||||||
this._value = __v_isShallow ? value : toReactive(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get value() {
|
get value() {
|
||||||
|
@ -131,7 +130,9 @@ class RefImpl<T = any> {
|
||||||
set value(newValue) {
|
set value(newValue) {
|
||||||
const oldValue = this._rawValue
|
const oldValue = this._rawValue
|
||||||
const useDirectValue =
|
const useDirectValue =
|
||||||
this.__v_isShallow || isShallow(newValue) || isReadonly(newValue)
|
this[ReactiveFlags.IS_SHALLOW] ||
|
||||||
|
isShallow(newValue) ||
|
||||||
|
isReadonly(newValue)
|
||||||
newValue = useDirectValue ? newValue : toRaw(newValue)
|
newValue = useDirectValue ? newValue : toRaw(newValue)
|
||||||
if (hasChanged(newValue, oldValue)) {
|
if (hasChanged(newValue, oldValue)) {
|
||||||
this._rawValue = newValue
|
this._rawValue = newValue
|
||||||
|
@ -277,7 +278,7 @@ class CustomRefImpl<T> {
|
||||||
private readonly _get: ReturnType<CustomRefFactory<T>>['get']
|
private readonly _get: ReturnType<CustomRefFactory<T>>['get']
|
||||||
private readonly _set: ReturnType<CustomRefFactory<T>>['set']
|
private readonly _set: ReturnType<CustomRefFactory<T>>['set']
|
||||||
|
|
||||||
public readonly __v_isRef = true
|
public readonly [ReactiveFlags.IS_REF] = true
|
||||||
|
|
||||||
constructor(factory: CustomRefFactory<T>) {
|
constructor(factory: CustomRefFactory<T>) {
|
||||||
const dep = (this.dep = new Dep())
|
const dep = (this.dep = new Dep())
|
||||||
|
@ -330,7 +331,7 @@ export function toRefs<T extends object>(object: T): ToRefs<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ObjectRefImpl<T extends object, K extends keyof T> {
|
class ObjectRefImpl<T extends object, K extends keyof T> {
|
||||||
public readonly __v_isRef = true
|
public readonly [ReactiveFlags.IS_REF] = true
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _object: T,
|
private readonly _object: T,
|
||||||
|
@ -353,8 +354,8 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetterRefImpl<T> {
|
class GetterRefImpl<T> {
|
||||||
public readonly __v_isRef = true
|
public readonly [ReactiveFlags.IS_REF] = true
|
||||||
public readonly __v_isReadonly = true
|
public readonly [ReactiveFlags.IS_READONLY] = true
|
||||||
constructor(private readonly _getter: () => T) {}
|
constructor(private readonly _getter: () => T) {}
|
||||||
get value() {
|
get value() {
|
||||||
return this._getter()
|
return this._getter()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ReactiveFlags } from '@vue/reactivity'
|
||||||
import {
|
import {
|
||||||
isArray,
|
isArray,
|
||||||
isFunction,
|
isFunction,
|
||||||
|
@ -28,7 +29,7 @@ export const toDisplayString = (val: unknown): string => {
|
||||||
|
|
||||||
const replacer = (_key: string, val: any): any => {
|
const replacer = (_key: string, val: any): any => {
|
||||||
// can't use isRef here since @vue/shared has no deps
|
// can't use isRef here since @vue/shared has no deps
|
||||||
if (val && val.__v_isRef) {
|
if (val && val[ReactiveFlags.IS_REF]) {
|
||||||
return replacer(_key, val.value)
|
return replacer(_key, val.value)
|
||||||
} else if (isMap(val)) {
|
} else if (isMap(val)) {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue