feat(reactivity): add shallowReactive function (#689)

This commit is contained in:
Dmitry Sharshakov
2020-02-04 18:15:27 +03:00
committed by GitHub
parent 2d56dfdc4f
commit 7f38c1e0ff
4 changed files with 44 additions and 3 deletions

View File

@@ -2,7 +2,8 @@ import { isObject, toRawType } from '@vue/shared'
import {
mutableHandlers,
readonlyHandlers,
shallowReadonlyHandlers
shallowReadonlyHandlers,
shallowReactiveHandlers
} from './baseHandlers'
import {
mutableCollectionHandlers,
@@ -75,7 +76,6 @@ export function readonly<T extends object>(
)
}
// @internal
// Return a reactive-copy of the original object, where only the root level
// properties are readonly, and does NOT unwrap refs nor recursively convert
// returned properties.
@@ -92,6 +92,19 @@ export function shallowReadonly<T extends object>(
)
}
// Return a reactive-copy of the original object, where only the root level
// properties are reactive, and does NOT unwrap refs nor recursively convert
// returned properties.
export function shallowReactive<T extends object>(target: T): T {
return createReactiveObject(
target,
rawToReactive,
reactiveToRaw,
shallowReactiveHandlers,
mutableCollectionHandlers
)
}
function createReactiveObject(
target: unknown,
toProxy: WeakMap<any, any>,