feat(reactivity): add isShallow api

This commit is contained in:
Evan You
2022-01-18 09:17:22 +08:00
parent 0c06c748a5
commit 9fda9411ec
9 changed files with 39 additions and 15 deletions

View File

@@ -16,10 +16,6 @@ export interface Ref<T = any> {
* autocomplete, so we use a private Symbol instead.
*/
[RefSymbol]: true
/**
* @internal
*/
_shallow?: boolean
}
type RefBase<T> = {
@@ -102,9 +98,9 @@ class RefImpl<T> {
public dep?: Dep = undefined
public readonly __v_isRef = true
constructor(value: T, public readonly _shallow: boolean) {
this._rawValue = _shallow ? value : toRaw(value)
this._value = _shallow ? value : toReactive(value)
constructor(value: T, public readonly __v_isShallow: boolean) {
this._rawValue = __v_isShallow ? value : toRaw(value)
this._value = __v_isShallow ? value : toReactive(value)
}
get value() {
@@ -113,10 +109,10 @@ class RefImpl<T> {
}
set value(newVal) {
newVal = this._shallow ? newVal : toRaw(newVal)
newVal = this.__v_isShallow ? newVal : toRaw(newVal)
if (hasChanged(newVal, this._rawValue)) {
this._rawValue = newVal
this._value = this._shallow ? newVal : toReactive(newVal)
this._value = this.__v_isShallow ? newVal : toReactive(newVal)
triggerRefValue(this, newVal)
}
}