@@ -211,10 +211,14 @@ class DatabaseRef extends ReferenceBase {
211
211
} )
212
212
}
213
213
214
- off ( evt = '' ) {
214
+ off ( evt = '' , origCB ) {
215
215
const path = this . dbPath ( ) ;
216
- return this . db . off ( path , evt )
216
+ return this . db . off ( path , evt , origCB )
217
217
. then ( ( { callback, subscriptions} ) => {
218
+ if ( dbSubscriptions [ path ] [ evt ] . length > 0 ) {
219
+ return subscriptions ;
220
+ }
221
+
218
222
return promisify ( 'off' , FirestackDatabase ) ( path , evt )
219
223
. then ( ( ) => {
220
224
// subscriptions.forEach(sub => sub.remove());
@@ -432,15 +436,20 @@ export class Database extends Base {
432
436
return Promise . resolve ( { callback, subscriptions} ) ;
433
437
}
434
438
435
- off ( path , evt ) {
439
+ off ( path , evt , origCB ) {
436
440
const key = this . _pathKey ( path ) ;
437
441
// Remove subscription
438
442
if ( dbSubscriptions [ key ] ) {
439
443
if ( ! evt || evt === "" ) {
440
444
dbSubscriptions [ key ] = { } ;
441
445
} else if ( dbSubscriptions [ key ] [ evt ] ) {
442
- delete dbSubscriptions [ key ] [ evt ] ;
446
+ if ( origCB ) {
447
+ dbSubscriptions [ key ] [ evt ] . splice ( dbSubscriptions [ key ] [ evt ] . indexOf ( origCB ) , 1 ) ;
448
+ } else {
449
+ delete dbSubscriptions [ key ] [ evt ] ;
450
+ }
443
451
}
452
+
444
453
if ( Object . keys ( dbSubscriptions [ key ] ) . length <= 0 ) {
445
454
// there are no more subscriptions
446
455
// so we can unwatch
0 commit comments