fix(reactivity): toRef
should not wrap a ref
(#2103)
This commit is contained in:
parent
aa8dc9a507
commit
d4bf9bcbb4
@ -236,6 +236,10 @@ describe('reactivity/ref', () => {
|
|||||||
// mutating source should trigger effect using the proxy refs
|
// mutating source should trigger effect using the proxy refs
|
||||||
a.x = 4
|
a.x = 4
|
||||||
expect(dummyX).toBe(4)
|
expect(dummyX).toBe(4)
|
||||||
|
|
||||||
|
// should keep ref
|
||||||
|
const r = { x: ref(1) }
|
||||||
|
expect(toRef(r, 'x')).toBe(r.x)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('toRefs', () => {
|
test('toRefs', () => {
|
||||||
|
@ -168,7 +168,9 @@ export function toRef<T extends object, K extends keyof T>(
|
|||||||
object: T,
|
object: T,
|
||||||
key: K
|
key: K
|
||||||
): Ref<T[K]> {
|
): Ref<T[K]> {
|
||||||
return new ObjectRefImpl(object, key) as any
|
return isRef(object[key])
|
||||||
|
? object[key]
|
||||||
|
: (new ObjectRefImpl(object, key) as any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// corner case when use narrows type
|
// corner case when use narrows type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user