@@ -71,12 +71,9 @@ export default class Database extends Base {
7171 const handle = this . _handle ( path , modifiersString ) ;
7272 this . log . debug ( 'adding on listener' , handle ) ;
7373
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 ) ;
8077
8178 return promisify ( 'on' , FirestackDatabase ) ( path , modifiersString , modifiers , eventName ) ;
8279 }
@@ -100,16 +97,14 @@ export default class Database extends Base {
10097
10198 if ( eventName && origCB ) {
10299 const i = this . subscriptions [ handle ] [ eventName ] . indexOf ( origCB ) ;
100+
103101 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 ) ;
105103 return Promise . resolve ( ) ;
106104 }
107105
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 ( ) ;
113108 } else if ( eventName ) {
114109 this . subscriptions [ handle ] [ eventName ] = [ ] ;
115110 } else {
0 commit comments