@@ -23,14 +23,15 @@ var uid = 0
2323
2424function Watcher ( vm , expression , cb , options ) {
2525 this . vm = vm
26- vm . _watcherList . push ( this )
26+ vm . _watchers . push ( this )
2727 this . expression = expression
28- this . cbs = [ cb ]
28+ this . cb = cb
2929 this . id = ++ uid // uid for batching
3030 this . active = true
3131 options = options || { }
3232 this . deep = ! ! options . deep
3333 this . user = ! ! options . user
34+ this . twoWay = ! ! options . twoWay
3435 this . deps = [ ]
3536 this . newDeps = [ ]
3637 // setup filters if any.
@@ -174,46 +175,11 @@ p.run = function () {
174175 ) {
175176 var oldValue = this . value
176177 this . value = value
177- var cbs = this . cbs
178- for ( var i = 0 , l = cbs . length ; i < l ; i ++ ) {
179- cbs [ i ] ( value , oldValue )
180- // if a callback also removed other callbacks,
181- // we need to adjust the loop accordingly.
182- var removed = l - cbs . length
183- if ( removed ) {
184- i -= removed
185- l -= removed
186- }
187- }
178+ this . cb ( value , oldValue )
188179 }
189180 }
190181}
191182
192- /**
193- * Add a callback.
194- *
195- * @param {Function } cb
196- */
197-
198- p . addCb = function ( cb ) {
199- this . cbs . push ( cb )
200- }
201-
202- /**
203- * Remove a callback.
204- *
205- * @param {Function } cb
206- */
207-
208- p . removeCb = function ( cb ) {
209- var cbs = this . cbs
210- if ( cbs . length > 1 ) {
211- cbs . $remove ( cb )
212- } else if ( cb === cbs [ 0 ] ) {
213- this . teardown ( )
214- }
215- }
216-
217183/**
218184 * Remove self from all dependencies' subcriber list.
219185 */
@@ -224,14 +190,14 @@ p.teardown = function () {
224190 // we can skip this if the vm if being destroyed
225191 // which can improve teardown performance.
226192 if ( ! this . vm . _isBeingDestroyed ) {
227- this . vm . _watcherList . $remove ( this )
193+ this . vm . _watchers . $remove ( this )
228194 }
229195 var i = this . deps . length
230196 while ( i -- ) {
231197 this . deps [ i ] . removeSub ( this )
232198 }
233199 this . active = false
234- this . vm = this . cbs = this . value = null
200+ this . vm = this . cb = this . value = null
235201 }
236202}
237203
0 commit comments