}
}
-// props handlers are special in the sense that it should not unwrap top-level
+// 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.
export const shallowReadonlyHandlers: ProxyHandler<object> = {
-import { isObject, toRawType, EMPTY_OBJ } from '@vue/shared'
+import { isObject, toRawType } from '@vue/shared'
import {
mutableHandlers,
readonlyHandlers,
// @internal
// Return a reactive-copy of the original object, where only the root level
-// properties are readonly, and does not recursively convert returned properties.
+// properties are readonly, and does NOT unwrap refs nor recursively convert
+// returned properties.
// This is used for creating the props proxy object for stateful components.
export function shallowReadonly<T extends object>(
target: T
if (!canObserve(target)) {
return target
}
- const handlers = __SSR__
- ? // disable reactivity in SSR.
- // NOTE: a potential caveat here is isReactive check may return different
- // values on nested values on client/server. This should be very rare but
- // we should keep an eye on this.
- EMPTY_OBJ
- : collectionTypes.has(target.constructor)
- ? collectionHandlers
- : baseHandlers
+ const handlers = collectionTypes.has(target.constructor)
+ ? collectionHandlers
+ : baseHandlers
observed = new Proxy(target, handlers)
toProxy.set(target, observed)
toRaw.set(observed, target)
return value
}
value = convert(value)
-
- if (__SSR__) {
- return {
- _isRef: true,
- value
- }
- }
-
const r = {
_isRef: true,
get value() {
export function toRefs<T extends object>(
object: T
): { [K in keyof T]: Ref<T[K]> } {
- if (__DEV__ && !__SSR__ && !isReactive(object)) {
+ if (__DEV__ && !isReactive(object)) {
console.warn(`toRefs() expects a reactive object but received a plain one.`)
}
const ret: any = {}