feat(reactivity): add shallowReactive function (#689)
This commit is contained in:
committed by
GitHub
parent
2d56dfdc4f
commit
7f38c1e0ff
@@ -12,6 +12,7 @@ const builtInSymbols = new Set(
|
||||
)
|
||||
|
||||
const get = /*#__PURE__*/ createGetter()
|
||||
const shallowReactiveGet = /*#__PURE__*/ createGetter(false, true)
|
||||
const readonlyGet = /*#__PURE__*/ createGetter(true)
|
||||
const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true)
|
||||
|
||||
@@ -54,6 +55,7 @@ function createGetter(isReadonly = false, shallow = false) {
|
||||
}
|
||||
|
||||
const set = /*#__PURE__*/ createSetter()
|
||||
const shallowReactiveSet = /*#__PURE__*/ createSetter(false, true)
|
||||
const readonlySet = /*#__PURE__*/ createSetter(true)
|
||||
const shallowReadonlySet = /*#__PURE__*/ createSetter(true, true)
|
||||
|
||||
@@ -165,6 +167,12 @@ export const readonlyHandlers: ProxyHandler<object> = {
|
||||
}
|
||||
}
|
||||
|
||||
export const shallowReactiveHandlers: ProxyHandler<object> = {
|
||||
...mutableHandlers,
|
||||
get: shallowReactiveGet,
|
||||
set: shallowReactiveSet
|
||||
}
|
||||
|
||||
// Props handlers are special in the sense that it should not unwrap top-level
|
||||
// refs (in order to allow refs to be explicitly passed down), but should
|
||||
// retain the reactivity of the normal readonly object.
|
||||
|
||||
Reference in New Issue
Block a user