File tree Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -62,21 +62,23 @@ exports.$delete = function (key) {
62
62
*
63
63
* @param {String } exp
64
64
* @param {Function } cb
65
- * @param {Boolean } [deep]
66
- * @param {Boolean } [immediate]
65
+ * @param {Object } [options]
66
+ * - {Boolean} deep
67
+ * - {Boolean} immediate
68
+ * - {Boolean} user
67
69
* @return {Function } - unwatchFn
68
70
*/
69
71
70
- exports . $watch = function ( exp , cb , deep , immediate ) {
72
+ exports . $watch = function ( exp , cb , options ) {
71
73
var vm = this
72
74
var wrappedCb = function ( val , oldVal ) {
73
75
cb . call ( vm , val , oldVal )
74
76
}
75
77
var watcher = new Watcher ( vm , exp , wrappedCb , {
76
- deep : deep ,
77
- user : true
78
+ deep : options && options . deep ,
79
+ user : ! options || options . user !== false
78
80
} )
79
- if ( immediate ) {
81
+ if ( options && options . immediate ) {
80
82
wrappedCb ( watcher . value )
81
83
}
82
84
return function unwatchFn ( ) {
@@ -147,4 +149,4 @@ exports.$log = function (path) {
147
149
data = JSON . parse ( JSON . stringify ( data ) )
148
150
}
149
151
console . log ( data )
150
- }
152
+ }
Original file line number Diff line number Diff line change @@ -136,4 +136,4 @@ function createAssetRegisters (Constructor) {
136
136
}
137
137
}
138
138
139
- createAssetRegisters ( exports )
139
+ createAssetRegisters ( exports )
Original file line number Diff line number Diff line change @@ -89,7 +89,9 @@ describe('Data API', function () {
89
89
it ( '$watch' , function ( done ) {
90
90
var spy = jasmine . createSpy ( )
91
91
// test immediate invoke
92
- var unwatch = vm . $watch ( 'a + b.c' , spy , false , true )
92
+ var unwatch = vm . $watch ( 'a + b.c' , spy , {
93
+ immediate : true
94
+ } )
93
95
expect ( spy ) . toHaveBeenCalledWith ( 3 , undefined )
94
96
vm . a = 2
95
97
nextTick ( function ( ) {
@@ -109,7 +111,7 @@ describe('Data API', function () {
109
111
// test immediate invoke
110
112
var unwatch = vm . $watch ( function ( ) {
111
113
return this . a + this . b . c
112
- } , spy , false , true )
114
+ } , spy , { immediate : true } )
113
115
expect ( spy ) . toHaveBeenCalledWith ( 3 , undefined )
114
116
vm . a = 2
115
117
nextTick ( function ( ) {
@@ -127,7 +129,9 @@ describe('Data API', function () {
127
129
it ( 'deep $watch' , function ( done ) {
128
130
var oldB = vm . b
129
131
var spy = jasmine . createSpy ( )
130
- vm . $watch ( 'b' , spy , true )
132
+ vm . $watch ( 'b' , spy , {
133
+ deep : true
134
+ } )
131
135
vm . b . c = 3
132
136
nextTick ( function ( ) {
133
137
expect ( spy ) . toHaveBeenCalledWith ( oldB , oldB )
You can’t perform that action at this time.
0 commit comments