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) {
5959 var oldData = this . _data
6060 this . _data = newData
6161 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+ }
6271 // unproxy keys not present in new data
6372 keys = Object . keys ( oldData )
6473 i = keys . length
Original file line number Diff line number Diff line change @@ -31,6 +31,32 @@ describe('Instance Scope', function () {
3131
3232 } )
3333
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+
3460 describe ( 'computed' , function ( ) {
3561
3662 var Test = Vue . extend ( {
You can’t perform that action at this time.
0 commit comments