@@ -71,12 +71,9 @@ export default class Database extends Base {
71
71
const handle = this . _handle ( path , modifiersString ) ;
72
72
this . log . debug ( 'adding on listener' , handle ) ;
73
73
74
- if ( this . subscriptions [ handle ] ) {
75
- if ( this . subscriptions [ handle ] [ eventName ] ) this . subscriptions [ handle ] [ eventName ] . push ( cb ) ;
76
- else this . subscriptions [ handle ] [ eventName ] = [ cb ] ;
77
- } else {
78
- this . subscriptions [ handle ] = { [ eventName ] : [ cb ] } ;
79
- }
74
+ if ( ! this . subscriptions [ handle ] ) this . subscriptions [ handle ] = { } ;
75
+ if ( ! this . subscriptions [ handle ] [ eventName ] ) this . subscriptions [ handle ] [ eventName ] = [ ] ;
76
+ this . subscriptions [ handle ] [ eventName ] . push ( cb ) ;
80
77
81
78
return promisify ( 'on' , FirestackDatabase ) ( path , modifiersString , modifiers , eventName ) ;
82
79
}
@@ -100,16 +97,14 @@ export default class Database extends Base {
100
97
101
98
if ( eventName && origCB ) {
102
99
const i = this . subscriptions [ handle ] [ eventName ] . indexOf ( origCB ) ;
100
+
103
101
if ( i === - 1 ) {
104
- this . log . warn ( 'off() called, but the callback specifed is not listening at that location (bad path)' , handle , eventName ) ;
102
+ this . log . warn ( 'off() called, but the callback specified is not listening at that location (bad path)' , handle , eventName ) ;
105
103
return Promise . resolve ( ) ;
106
104
}
107
105
108
- this . subscriptions [ handle ] [ eventName ] = this . subscriptions [ handle ] [ eventName ] . splice ( i , 1 ) ;
109
-
110
- if ( this . subscriptions [ handle ] [ eventName ] . length > 0 ) {
111
- return Promise . resolve ( ) ;
112
- }
106
+ this . subscriptions [ handle ] [ eventName ] . splice ( i , 1 ) ;
107
+ if ( this . subscriptions [ handle ] [ eventName ] . length > 0 ) return Promise . resolve ( ) ;
113
108
} else if ( eventName ) {
114
109
this . subscriptions [ handle ] [ eventName ] = [ ] ;
115
110
} else {
0 commit comments