@@ -32,7 +32,7 @@ var ArrayProxy = Object.create(Array.prototype)
32
32
methods . forEach ( function ( method ) {
33
33
def ( ArrayProxy , method , function ( ) {
34
34
var result = Array . prototype [ method ] . apply ( this , arguments )
35
- this . __observer__ . emit ( 'mutate' , null , this , {
35
+ this . __emitter__ . emit ( 'mutate' , null , this , {
36
36
method : method ,
37
37
args : slice . call ( arguments ) ,
38
38
result : result
@@ -110,10 +110,10 @@ function watchObject (obj) {
110
110
* and add augmentations by intercepting the prototype chain
111
111
*/
112
112
function 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 )
117
117
}
118
118
if ( hasProto ) {
119
119
arr . __proto__ = ArrayProxy
@@ -142,8 +142,8 @@ function convert (obj, key) {
142
142
// emit set on bind
143
143
// this means when an object is observed it will emit
144
144
// a first batch of set events.
145
- var observer = obj . __observer__ ,
146
- values = observer . values
145
+ var emitter = obj . __emitter__ ,
146
+ values = emitter . values
147
147
148
148
init ( obj [ key ] )
149
149
@@ -152,13 +152,13 @@ function convert (obj, key) {
152
152
var value = values [ key ]
153
153
// only emit get on tip values
154
154
if ( pub . shouldGet && typeOf ( value ) !== OBJECT ) {
155
- observer . emit ( 'get' , key )
155
+ emitter . emit ( 'get' , key )
156
156
}
157
157
return value
158
158
} ,
159
159
set : function ( newVal ) {
160
160
var oldVal = values [ key ]
161
- unobserve ( oldVal , key , observer )
161
+ unobserve ( oldVal , key , emitter )
162
162
copyPaths ( newVal , oldVal )
163
163
// an immediate property should notify its parent
164
164
// to emit set for itself too
@@ -168,11 +168,11 @@ function convert (obj, key) {
168
168
169
169
function init ( val , propagate ) {
170
170
values [ key ] = val
171
- observer . emit ( 'set' , key , val , propagate )
171
+ emitter . emit ( 'set' , key , val , propagate )
172
172
if ( Array . isArray ( val ) ) {
173
- observer . emit ( 'set' , key + '.length' , val . length )
173
+ emitter . emit ( 'set' , key + '.length' , val . length )
174
174
}
175
- observe ( val , key , observer )
175
+ observe ( val , key , emitter )
176
176
}
177
177
}
178
178
@@ -193,7 +193,7 @@ function isWatchable (obj) {
193
193
*/
194
194
function emitSet ( obj ) {
195
195
var type = typeOf ( obj ) ,
196
- emitter = obj && obj . __observer__
196
+ emitter = obj && obj . __emitter__
197
197
if ( type === ARRAY ) {
198
198
emitter . emit ( 'set' , 'length' , obj . length )
199
199
} else if ( type === OBJECT ) {
@@ -243,15 +243,15 @@ function ensurePath (obj, key) {
243
243
sec = path [ i ]
244
244
if ( ! obj [ sec ] ) {
245
245
obj [ sec ] = { }
246
- if ( obj . __observer__ ) convert ( obj , sec )
246
+ if ( obj . __emitter__ ) convert ( obj , sec )
247
247
}
248
248
obj = obj [ sec ]
249
249
}
250
250
if ( typeOf ( obj ) === OBJECT ) {
251
251
sec = path [ i ]
252
252
if ( ! ( sec in obj ) ) {
253
253
obj [ sec ] = undefined
254
- if ( obj . __observer__ ) convert ( obj , sec )
254
+ if ( obj . __emitter__ ) convert ( obj , sec )
255
255
}
256
256
}
257
257
}
@@ -260,54 +260,54 @@ function ensurePath (obj, key) {
260
260
* Observe an object with a given path,
261
261
* and proxy get/set/mutate events to the provided observer.
262
262
*/
263
- function observe ( obj , rawPath , parentOb ) {
263
+ function observe ( obj , rawPath , observer ) {
264
264
265
265
if ( ! isWatchable ( obj ) ) return
266
266
267
267
var path = rawPath ? rawPath + '.' : '' ,
268
- alreadyConverted = ! ! obj . __observer__ ,
269
- childOb
268
+ alreadyConverted = ! ! obj . __emitter__ ,
269
+ emitter
270
270
271
271
if ( ! alreadyConverted ) {
272
- def ( obj , '__observer__ ' , new Emitter ( ) )
272
+ def ( obj , '__emitter__ ' , new Emitter ( ) )
273
273
}
274
274
275
- childOb = obj . __observer__
276
- childOb . values = childOb . values || utils . hash ( )
275
+ emitter = obj . __emitter__
276
+ emitter . values = emitter . values || utils . hash ( )
277
277
278
278
// setup proxy listeners on the parent observer.
279
279
// we need to keep reference to them so that they
280
280
// 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 ] = {
283
283
get : function ( key ) {
284
- parentOb . emit ( 'get' , path + key )
284
+ observer . emit ( 'get' , path + key )
285
285
} ,
286
286
set : function ( key , val , propagate ) {
287
- parentOb . emit ( 'set' , path + key , val )
287
+ observer . emit ( 'set' , path + key , val )
288
288
// also notify observer that the object itself changed
289
289
// but only do so when it's a immediate property. this
290
290
// avoids duplicate event firing.
291
291
if ( rawPath && propagate ) {
292
- parentOb . emit ( 'set' , rawPath , obj , true )
292
+ observer . emit ( 'set' , rawPath , obj , true )
293
293
}
294
294
} ,
295
295
mutate : function ( key , val , mutation ) {
296
296
// if the Array is a root value
297
297
// the key will be null
298
298
var fixedPath = key ? path + key : rawPath
299
- parentOb . emit ( 'mutate' , fixedPath , val , mutation )
299
+ observer . emit ( 'mutate' , fixedPath , val , mutation )
300
300
// also emit set for Array's length when it mutates
301
301
var m = mutation . method
302
302
if ( m !== 'sort' && m !== 'reverse' ) {
303
- parentOb . emit ( 'set' , fixedPath + '.length' , val . length )
303
+ observer . emit ( 'set' , fixedPath + '.length' , val . length )
304
304
}
305
305
}
306
306
}
307
307
308
308
// attach the listeners to the child observer.
309
309
// now all the events will propagate upwards.
310
- childOb
310
+ emitter
311
311
. on ( 'get' , proxies . get )
312
312
. on ( 'set' , proxies . set )
313
313
. on ( 'mutate' , proxies . mutate )
@@ -331,14 +331,14 @@ function observe (obj, rawPath, parentOb) {
331
331
*/
332
332
function unobserve ( obj , path , observer ) {
333
333
334
- if ( ! obj || ! obj . __observer__ ) return
334
+ if ( ! obj || ! obj . __emitter__ ) return
335
335
336
336
path = path ? path + '.' : ''
337
337
var proxies = observer . proxies [ path ]
338
338
if ( ! proxies ) return
339
339
340
340
// turn off listeners
341
- obj . __observer__
341
+ obj . __emitter__
342
342
. off ( 'get' , proxies . get )
343
343
. off ( 'set' , proxies . set )
344
344
. off ( 'mutate' , proxies . mutate )
0 commit comments