@@ -32,7 +32,7 @@ var ArrayProxy = Object.create(Array.prototype)
3232methods . forEach ( function ( method ) {
3333 def ( ArrayProxy , method , function ( ) {
3434 var result = Array . prototype [ method ] . apply ( this , arguments )
35- this . __observer__ . emit ( 'mutate' , null , this , {
35+ this . __emitter__ . emit ( 'mutate' , null , this , {
3636 method : method ,
3737 args : slice . call ( arguments ) ,
3838 result : result
@@ -110,10 +110,10 @@ function watchObject (obj) {
110110 * and add augmentations by intercepting the prototype chain
111111 */
112112function watchArray ( arr ) {
113- var observer = arr . __observer__
114- if ( ! observer ) {
115- observer = new Emitter ( )
116- def ( arr , '__observer__ ' , observer )
113+ var emitter = arr . __emitter__
114+ if ( ! emitter ) {
115+ emitter = new Emitter ( )
116+ def ( arr , '__emitter__ ' , emitter )
117117 }
118118 if ( hasProto ) {
119119 arr . __proto__ = ArrayProxy
@@ -142,8 +142,8 @@ function convert (obj, key) {
142142 // emit set on bind
143143 // this means when an object is observed it will emit
144144 // a first batch of set events.
145- var observer = obj . __observer__ ,
146- values = observer . values
145+ var emitter = obj . __emitter__ ,
146+ values = emitter . values
147147
148148 init ( obj [ key ] )
149149
@@ -152,13 +152,13 @@ function convert (obj, key) {
152152 var value = values [ key ]
153153 // only emit get on tip values
154154 if ( pub . shouldGet && typeOf ( value ) !== OBJECT ) {
155- observer . emit ( 'get' , key )
155+ emitter . emit ( 'get' , key )
156156 }
157157 return value
158158 } ,
159159 set : function ( newVal ) {
160160 var oldVal = values [ key ]
161- unobserve ( oldVal , key , observer )
161+ unobserve ( oldVal , key , emitter )
162162 copyPaths ( newVal , oldVal )
163163 // an immediate property should notify its parent
164164 // to emit set for itself too
@@ -168,11 +168,11 @@ function convert (obj, key) {
168168
169169 function init ( val , propagate ) {
170170 values [ key ] = val
171- observer . emit ( 'set' , key , val , propagate )
171+ emitter . emit ( 'set' , key , val , propagate )
172172 if ( Array . isArray ( val ) ) {
173- observer . emit ( 'set' , key + '.length' , val . length )
173+ emitter . emit ( 'set' , key + '.length' , val . length )
174174 }
175- observe ( val , key , observer )
175+ observe ( val , key , emitter )
176176 }
177177}
178178
@@ -193,7 +193,7 @@ function isWatchable (obj) {
193193 */
194194function emitSet ( obj ) {
195195 var type = typeOf ( obj ) ,
196- emitter = obj && obj . __observer__
196+ emitter = obj && obj . __emitter__
197197 if ( type === ARRAY ) {
198198 emitter . emit ( 'set' , 'length' , obj . length )
199199 } else if ( type === OBJECT ) {
@@ -243,15 +243,15 @@ function ensurePath (obj, key) {
243243 sec = path [ i ]
244244 if ( ! obj [ sec ] ) {
245245 obj [ sec ] = { }
246- if ( obj . __observer__ ) convert ( obj , sec )
246+ if ( obj . __emitter__ ) convert ( obj , sec )
247247 }
248248 obj = obj [ sec ]
249249 }
250250 if ( typeOf ( obj ) === OBJECT ) {
251251 sec = path [ i ]
252252 if ( ! ( sec in obj ) ) {
253253 obj [ sec ] = undefined
254- if ( obj . __observer__ ) convert ( obj , sec )
254+ if ( obj . __emitter__ ) convert ( obj , sec )
255255 }
256256 }
257257}
@@ -260,54 +260,54 @@ function ensurePath (obj, key) {
260260 * Observe an object with a given path,
261261 * and proxy get/set/mutate events to the provided observer.
262262 */
263- function observe ( obj , rawPath , parentOb ) {
263+ function observe ( obj , rawPath , observer ) {
264264
265265 if ( ! isWatchable ( obj ) ) return
266266
267267 var path = rawPath ? rawPath + '.' : '' ,
268- alreadyConverted = ! ! obj . __observer__ ,
269- childOb
268+ alreadyConverted = ! ! obj . __emitter__ ,
269+ emitter
270270
271271 if ( ! alreadyConverted ) {
272- def ( obj , '__observer__ ' , new Emitter ( ) )
272+ def ( obj , '__emitter__ ' , new Emitter ( ) )
273273 }
274274
275- childOb = obj . __observer__
276- childOb . values = childOb . values || utils . hash ( )
275+ emitter = obj . __emitter__
276+ emitter . values = emitter . values || utils . hash ( )
277277
278278 // setup proxy listeners on the parent observer.
279279 // we need to keep reference to them so that they
280280 // can be removed when the object is un-observed.
281- parentOb . proxies = parentOb . proxies || { }
282- var proxies = parentOb . proxies [ path ] = {
281+ observer . proxies = observer . proxies || { }
282+ var proxies = observer . proxies [ path ] = {
283283 get : function ( key ) {
284- parentOb . emit ( 'get' , path + key )
284+ observer . emit ( 'get' , path + key )
285285 } ,
286286 set : function ( key , val , propagate ) {
287- parentOb . emit ( 'set' , path + key , val )
287+ observer . emit ( 'set' , path + key , val )
288288 // also notify observer that the object itself changed
289289 // but only do so when it's a immediate property. this
290290 // avoids duplicate event firing.
291291 if ( rawPath && propagate ) {
292- parentOb . emit ( 'set' , rawPath , obj , true )
292+ observer . emit ( 'set' , rawPath , obj , true )
293293 }
294294 } ,
295295 mutate : function ( key , val , mutation ) {
296296 // if the Array is a root value
297297 // the key will be null
298298 var fixedPath = key ? path + key : rawPath
299- parentOb . emit ( 'mutate' , fixedPath , val , mutation )
299+ observer . emit ( 'mutate' , fixedPath , val , mutation )
300300 // also emit set for Array's length when it mutates
301301 var m = mutation . method
302302 if ( m !== 'sort' && m !== 'reverse' ) {
303- parentOb . emit ( 'set' , fixedPath + '.length' , val . length )
303+ observer . emit ( 'set' , fixedPath + '.length' , val . length )
304304 }
305305 }
306306 }
307307
308308 // attach the listeners to the child observer.
309309 // now all the events will propagate upwards.
310- childOb
310+ emitter
311311 . on ( 'get' , proxies . get )
312312 . on ( 'set' , proxies . set )
313313 . on ( 'mutate' , proxies . mutate )
@@ -331,14 +331,14 @@ function observe (obj, rawPath, parentOb) {
331331 */
332332function unobserve ( obj , path , observer ) {
333333
334- if ( ! obj || ! obj . __observer__ ) return
334+ if ( ! obj || ! obj . __emitter__ ) return
335335
336336 path = path ? path + '.' : ''
337337 var proxies = observer . proxies [ path ]
338338 if ( ! proxies ) return
339339
340340 // turn off listeners
341- obj . __observer__
341+ obj . __emitter__
342342 . off ( 'get' , proxies . get )
343343 . off ( 'set' , proxies . set )
344344 . off ( 'mutate' , proxies . mutate )
0 commit comments