Skip to content

Commit 8c424f5

Browse files
committed
Support removing multiple storage listeners
1 parent 6a96514 commit 8c424f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/modules/storage/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,23 @@ export default class Storage extends Base {
7373
}
7474

7575
_removeListener(path: string, eventName: string, origCB: (evt: Object) => Object) {
76-
if (this.subscriptions[path] && this.subscriptions[path][eventName]) {
76+
if (!this.subscriptions[path] || (eventName && !this.subscriptions[path][eventName])) {
77+
this.log.warn('_removeListener() called, but not currently listening at that location (bad path)', path, eventName);
78+
return Promise.resolve();
79+
}
80+
81+
if (eventName && origCB) {
7782
const i = this.subscriptions[path][eventName].indexOf(origCB);
7883

7984
if (i === -1) {
8085
this.log.warn('_removeListener() called, but the callback specified is not listening at this location (bad path)', path, eventName);
8186
} else {
8287
this.subscriptions[path][eventName].splice(i, 1);
8388
}
89+
} else if (eventName) {
90+
this.subscriptions[path][eventName] = [];
8491
} else {
85-
this.log.warn('_removeListener() called, but there are no listeners at this location (bad path)', path, eventName);
92+
this.subscriptions[path] = {}
8693
}
8794
}
8895

0 commit comments

Comments
 (0)