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

@@ -1,5 +1,6 @@
import {
isRef,
isShallow,
Ref,
ComputedRef,
ReactiveEffect,
@@ -205,7 +206,7 @@ function doWatch(
if (isRef(source)) {
getter = () => source.value
forceTrigger = !!source._shallow
forceTrigger = isShallow(source)
} else if (isReactive(source)) {
getter = () => source
deep = true

View File

@@ -1,5 +1,6 @@
import { isReactive, isReadonly, isRef, Ref, toRaw } from '@vue/reactivity'
import { EMPTY_OBJ, extend, isArray, isFunction, isObject } from '@vue/shared'
import { isShallow } from '../../reactivity/src/reactive'
import { ComponentInternalInstance, ComponentOptions } from './component'
import { ComponentPublicInstance } from './componentPublicInstance'
@@ -38,7 +39,7 @@ export function initCustomFormatter() {
return [
'div',
{},
['span', vueStyle, 'Reactive'],
['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
'<',
formatValue(obj),
`>${isReadonly(obj) ? ` (readonly)` : ``}`
@@ -47,7 +48,7 @@ export function initCustomFormatter() {
return [
'div',
{},
['span', vueStyle, 'Readonly'],
['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
'<',
formatValue(obj),
'>'
@@ -181,7 +182,7 @@ export function initCustomFormatter() {
}
function genRefFlag(v: Ref) {
if (v._shallow) {
if (isShallow(v)) {
return `ShallowRef`
}
if ((v as any).effect) {

View File

@@ -15,6 +15,7 @@ export {
isProxy,
isReactive,
isReadonly,
isShallow,
// advanced
customRef,
triggerRef,