feat(core): allow passing explicit refs via props
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { isObject, toRawType } from '@vue/shared'
|
||||
import { mutableHandlers, readonlyHandlers } from './baseHandlers'
|
||||
import {
|
||||
mutableHandlers,
|
||||
readonlyHandlers,
|
||||
readonlyPropsHandlers
|
||||
} from './baseHandlers'
|
||||
import {
|
||||
mutableCollectionHandlers,
|
||||
readonlyCollectionHandlers
|
||||
@@ -80,6 +84,23 @@ export function readonly<T extends object>(
|
||||
)
|
||||
}
|
||||
|
||||
// @internal
|
||||
// Return a readonly-copy of a props object, without unwrapping refs at the root
|
||||
// level. This is intended to allow explicitly passing refs as props.
|
||||
// Technically this should use different global cache from readonly(), but
|
||||
// since it is only used on internal objects so it's not really necessary.
|
||||
export function readonlyProps<T extends object>(
|
||||
target: T
|
||||
): Readonly<{ [K in keyof T]: UnwrapNestedRefs<T[K]> }> {
|
||||
return createReactiveObject(
|
||||
target,
|
||||
rawToReadonly,
|
||||
readonlyToRaw,
|
||||
readonlyPropsHandlers,
|
||||
readonlyCollectionHandlers
|
||||
)
|
||||
}
|
||||
|
||||
function createReactiveObject(
|
||||
target: unknown,
|
||||
toProxy: WeakMap<any, any>,
|
||||
|
||||
Reference in New Issue
Block a user