|
|
@@ -28,7 +28,9 @@ export interface Target {
|
|
|
}
|
|
|
|
|
|
export const reactiveMap = new WeakMap<Target, any>()
|
|
|
+export const shallowReactiveMap = new WeakMap<Target, any>()
|
|
|
export const readonlyMap = new WeakMap<Target, any>()
|
|
|
+export const shallowReadonlyMap = new WeakMap<Target, any>()
|
|
|
|
|
|
const enum TargetType {
|
|
|
INVALID = 0,
|
|
|
@@ -92,7 +94,8 @@ export function reactive(target: object) {
|
|
|
target,
|
|
|
false,
|
|
|
mutableHandlers,
|
|
|
- mutableCollectionHandlers
|
|
|
+ mutableCollectionHandlers,
|
|
|
+ reactiveMap
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -106,7 +109,8 @@ export function shallowReactive<T extends object>(target: T): T {
|
|
|
target,
|
|
|
false,
|
|
|
shallowReactiveHandlers,
|
|
|
- shallowCollectionHandlers
|
|
|
+ shallowCollectionHandlers,
|
|
|
+ shallowReactiveMap
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -143,7 +147,8 @@ export function readonly<T extends object>(
|
|
|
target,
|
|
|
true,
|
|
|
readonlyHandlers,
|
|
|
- readonlyCollectionHandlers
|
|
|
+ readonlyCollectionHandlers,
|
|
|
+ readonlyMap
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -160,7 +165,8 @@ export function shallowReadonly<T extends object>(
|
|
|
target,
|
|
|
true,
|
|
|
shallowReadonlyHandlers,
|
|
|
- shallowReadonlyCollectionHandlers
|
|
|
+ shallowReadonlyCollectionHandlers,
|
|
|
+ shallowReadonlyMap
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -168,7 +174,8 @@ function createReactiveObject(
|
|
|
target: Target,
|
|
|
isReadonly: boolean,
|
|
|
baseHandlers: ProxyHandler<any>,
|
|
|
- collectionHandlers: ProxyHandler<any>
|
|
|
+ collectionHandlers: ProxyHandler<any>,
|
|
|
+ proxyMap: WeakMap<Target, any>
|
|
|
) {
|
|
|
if (!isObject(target)) {
|
|
|
if (__DEV__) {
|
|
|
@@ -185,7 +192,6 @@ function createReactiveObject(
|
|
|
return target
|
|
|
}
|
|
|
// target already has corresponding Proxy
|
|
|
- const proxyMap = isReadonly ? readonlyMap : reactiveMap
|
|
|
const existingProxy = proxyMap.get(target)
|
|
|
if (existingProxy) {
|
|
|
return existingProxy
|