@@ -195,11 +195,17 @@ class DatabaseRef extends ReferenceBase {
195195 } ) ;
196196 }
197197
198- once ( evt = 'once' ) {
198+ once ( evt = 'once' , cb ) {
199199 const path = this . dbPath ( ) ;
200200 const modifiers = this . dbModifiers ( ) ;
201201 return promisify ( 'onOnce' , FirestackDatabase ) ( path , modifiers , evt )
202202 . then ( ( { snapshot} ) => new DataSnapshot ( this , snapshot ) )
203+ . then ( snapshot => {
204+ if ( cb && typeof cb === 'function' ) {
205+ cb ( snapshot ) ;
206+ }
207+ return snapshot ;
208+ } )
203209 }
204210
205211 off ( evt = '' ) {
@@ -208,7 +214,7 @@ class DatabaseRef extends ReferenceBase {
208214 . then ( ( { callback, subscriptions} ) => {
209215 return promisify ( 'off' , FirestackDatabase ) ( path , evt )
210216 . then ( ( ) => {
211- this . listeners [ evt ]
217+ // subscriptions.forEach(sub => sub.remove());
212218 delete this . listeners [ evt ] ;
213219 callback ( this ) ;
214220 return subscriptions ;
@@ -388,7 +394,7 @@ export class Database extends Base {
388394 }
389395
390396 const callback = ( ref ) => {
391- const key = this . _pathKey ( path ) ;
397+ const key = this . _pathKey ( ref . path ) ;
392398 this . refs [ key ] = ref ;
393399 }
394400 const subscriptions = [ this . successListener , this . errorListener ] ;
@@ -399,7 +405,9 @@ export class Database extends Base {
399405 const key = this . _pathKey ( path ) ;
400406 // Remove subscription
401407 if ( dbSubscriptions [ key ] ) {
402- if ( dbSubscriptions [ key ] [ evt ] ) {
408+ if ( ! evt || evt === "" ) {
409+ dbSubscriptions [ key ] = { } ;
410+ } else if ( dbSubscriptions [ key ] [ evt ] ) {
403411 delete dbSubscriptions [ key ] [ evt ] ;
404412 }
405413 if ( Object . keys ( dbSubscriptions [ key ] ) . length <= 0 ) {
@@ -419,7 +427,7 @@ export class Database extends Base {
419427 }
420428 }
421429 const callback = ( ref ) => {
422- const key = this . _pathKey ( path ) ;
430+ const key = this . _pathKey ( ref . path ) ;
423431 delete this . refs [ key ] ;
424432 }
425433 const subscriptions = [ this . successListener , this . errorListener ] ;
0 commit comments