File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,15 @@ exports._setData = function (newData) {
59
59
var oldData = this . _data
60
60
this . _data = newData
61
61
var keys , key , i
62
+ // copy props
63
+ var props = this . $options . props
64
+ if ( props ) {
65
+ i = props . length
66
+ while ( i -- ) {
67
+ key = props [ i ]
68
+ newData . $set ( key , oldData [ key ] )
69
+ }
70
+ }
62
71
// unproxy keys not present in new data
63
72
keys = Object . keys ( oldData )
64
73
i = keys . length
Original file line number Diff line number Diff line change @@ -31,6 +31,32 @@ describe('Instance Scope', function () {
31
31
32
32
} )
33
33
34
+ describe ( '$data' , function ( ) {
35
+
36
+ var vm = new Vue ( {
37
+ props : [ 'c' ] ,
38
+ data : {
39
+ a : 1
40
+ }
41
+ } )
42
+
43
+ it ( 'should initialize props' , function ( ) {
44
+ expect ( vm . hasOwnProperty ( 'c' ) ) . toBe ( true )
45
+ } )
46
+
47
+ it ( 'replace $data' , function ( ) {
48
+ vm . c = 3
49
+ vm . $data = { b : 2 }
50
+ // proxy new key
51
+ expect ( vm . b ) . toBe ( 2 )
52
+ // unproxy old key that's no longer present
53
+ expect ( vm . hasOwnProperty ( 'a' ) ) . toBe ( false )
54
+ // should copy props
55
+ expect ( vm . c ) . toBe ( 3 )
56
+ } )
57
+
58
+ } )
59
+
34
60
describe ( 'computed' , function ( ) {
35
61
36
62
var Test = Vue . extend ( {
You can’t perform that action at this time.
0 commit comments