@@ -4,7 +4,7 @@ dop.core.emitToObservers = function(mutations) {
44 var mutation ,
55 path_id ,
66 observer_id ,
7- observers = { } ,
7+ mutationsToEmitByIdObserver = { } ,
88 mutationsWithSubscribers = false ,
99 data_path = dop . data . path ,
1010 index = 0 ,
@@ -17,34 +17,37 @@ dop.core.emitToObservers = function(mutations) {
1717 if ( ! mutationsWithSubscribers && isObject ( dop . data . object [ dop . getObjectId ( mutation . object ) ] ) )
1818 mutationsWithSubscribers = true ;
1919
20-
20+ // .observers
2121 if ( data_path [ path_id ] !== undefined && data_path [ path_id ] . observers !== undefined ) {
2222 for ( observer_id in data_path [ path_id ] . observers ) {
23- if ( observers [ observer_id ] === undefined )
24- observers [ observer_id ] = [ ] ;
25- observers [ observer_id ] . push ( mutation ) ;
23+ if ( mutationsToEmitByIdObserver [ observer_id ] === undefined )
24+ mutationsToEmitByIdObserver [ observer_id ] = [ ] ;
25+ mutationsToEmitByIdObserver [ observer_id ] . push ( mutation ) ;
2626 }
2727 }
2828
29- // If mutation is swap type we should skip
30- if ( mutation . swaps === undefined ) {
29+ // .observers_prop
30+ if ( mutation . swaps === undefined ) { // If mutation is swaps type we should skip because does not have observers_prop and also the length never changes
3131 path_id += dop . core . pathSeparator ( mutation . splice === undefined ? mutation . prop : 'length' ) ;
3232 if ( data_path [ path_id ] !== undefined && data_path [ path_id ] . observers_prop !== undefined ) {
3333 for ( observer_id in data_path [ path_id ] . observers_prop ) {
34- if ( observers [ observer_id ] === undefined )
35- observers [ observer_id ] = [ ] ;
34+ if ( mutationsToEmitByIdObserver [ observer_id ] === undefined )
35+ mutationsToEmitByIdObserver [ observer_id ] = [ ] ;
3636 // We have to check this because we dont want to duplicate
37- if ( observers [ observer_id ] . indexOf ( mutation ) == - 1 )
38- observers [ observer_id ] . push ( mutation ) ;
37+ if ( mutationsToEmitByIdObserver [ observer_id ] . indexOf ( mutation ) == - 1 )
38+ mutationsToEmitByIdObserver [ observer_id ] . push ( mutation ) ;
3939 }
4040 }
4141 }
4242
4343 }
4444
4545 // Emiting
46- for ( observer_id in observers )
47- dop . data . observers [ observer_id ] . callback ( observers [ observer_id ] ) ;
46+ for ( observer_id in mutationsToEmitByIdObserver ) {
47+ var observer = dop . data . observers [ observer_id ] ;
48+ if ( observer !== undefined ) // We need to make sure that the observer still exists, because maybe has been removed after calling previous observers
49+ observer . callback ( mutationsToEmitByIdObserver [ observer_id ] ) ;
50+ }
4851
4952 return mutationsWithSubscribers ;
5053} ;
0 commit comments