File tree 2 files changed +33
-3
lines changed
2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { isRef } from './ref'
2
2
import { proxy , isFunction , isPlainObject , isArray } from '../utils'
3
- import { isReactive } from './reactive'
3
+ import { isReactive , isRaw } from './reactive'
4
4
5
5
export function unwrapRefProxy ( value : any , map = new WeakMap ( ) ) {
6
6
if ( map . has ( value ) ) {
@@ -13,7 +13,8 @@ export function unwrapRefProxy(value: any, map = new WeakMap()) {
13
13
isReactive ( value ) ||
14
14
! isPlainObject ( value ) ||
15
15
! Object . isExtensible ( value ) ||
16
- isRef ( value )
16
+ isRef ( value ) ||
17
+ isRaw ( value )
17
18
) {
18
19
return value
19
20
}
@@ -28,8 +29,12 @@ export function unwrapRefProxy(value: any, map = new WeakMap()) {
28
29
29
30
for ( const k of Object . keys ( value ) ) {
30
31
const r = value [ k ]
32
+ // don't process on falsy or raw
33
+ if ( ! r || isRaw ( r ) ) {
34
+ obj [ k ] = r
35
+ }
31
36
// if is a ref, create a proxy to retrieve the value,
32
- if ( isRef ( r ) ) {
37
+ else if ( isRef ( r ) ) {
33
38
const set = ( v : any ) => ( r . value = v )
34
39
const get = ( ) => r . value
35
40
Original file line number Diff line number Diff line change 7
7
inject,
8
8
reactive,
9
9
toRefs,
10
+ markRaw,
10
11
} = require ( '../src' )
11
12
12
13
describe ( 'setup' , ( ) => {
@@ -622,6 +623,30 @@ describe('setup', () => {
622
623
vm . $el . querySelector ( '#recursive_b_recursive_recursive_r' ) . textContent
623
624
) . toBe ( 'r' )
624
625
} )
626
+
627
+ // #384
628
+ it ( 'not unwrap when is raw' , ( ) => {
629
+ const vm = new Vue ( {
630
+ setup ( ) {
631
+ const xx = {
632
+ ref : ref ( 'r' ) ,
633
+ }
634
+ const r = markRaw ( xx )
635
+ return {
636
+ r,
637
+ }
638
+ } ,
639
+ template : `<div>
640
+ <p id="r">{{r}}</p>
641
+ </div>` ,
642
+ } ) . $mount ( )
643
+
644
+ expect ( JSON . parse ( vm . $el . querySelector ( '#r' ) . textContent ) ) . toMatchObject ( {
645
+ ref : {
646
+ value : 'r' ,
647
+ } ,
648
+ } )
649
+ } )
625
650
} )
626
651
627
652
it ( 'should not unwrap built-in objects on the template' , ( ) => {
You can’t perform that action at this time.
0 commit comments