diff --git a/lib/modules/database/index.js b/lib/modules/database/index.js index f804ecf1..89041ace 100644 --- a/lib/modules/database/index.js +++ b/lib/modules/database/index.js @@ -112,7 +112,7 @@ export default class Database extends Base { const promises = []; Object.keys(this.references).forEach((refId) => { const ref = this.references[refId]; - promises.push(this.off(Number(refId), Object.values(ref.listeners), 0)); + promises.push(this.off(Number(refId), Object.values(ref.refListeners), 0)); }); return Promise.all(promises); } @@ -157,8 +157,8 @@ export default class Database extends Base { const body = event.body || {}; const { refId, listenerId, path, eventName, snapshot } = body; this.log.debug('_handleDatabaseEvent: ', refId, listenerId, path, eventName, snapshot && snapshot.key); - if (this.references[refId] && this.references[refId].listeners[listenerId]) { - const cb = this.references[refId].listeners[listenerId].successCallback; + if (this.references[refId] && this.references[refId].refListeners[listenerId]) { + const cb = this.references[refId].refListeners[listenerId].successCallback; cb(new Snapshot(this.references[refId], snapshot)); } else { FirebaseDatabase.off(refId, [{ listenerId, eventName }], () => { @@ -203,8 +203,8 @@ export default class Database extends Base { this.log.debug('_handleDatabaseError ->', refId, listenerId, path, 'database_error', error); - if (this.references[refId] && this.references[refId].listeners[listenerId]) { - const failureCb = this.references[refId].listeners[listenerId].failureCallback; + if (this.references[refId] && this.references[refId].refListeners[listenerId]) { + const failureCb = this.references[refId].refListeners[listenerId].failureCallback; if (failureCb) failureCb(firebaseError); } } diff --git a/lib/modules/database/reference.js b/lib/modules/database/reference.js index 7051f355..0c4dfef6 100644 --- a/lib/modules/database/reference.js +++ b/lib/modules/database/reference.js @@ -56,14 +56,14 @@ const ReferenceEventTypes = { export default class Reference extends ReferenceBase { refId: number; - listeners: { [listenerId: number]: DatabaseListener }; + refListeners: { [listenerId: number]: DatabaseListener }; database: FirebaseDatabase; query: Query; constructor(database: FirebaseDatabase, path: string, existingModifiers?: Array) { super(path); this.refId = refId++; - this.listeners = {}; + this.refListeners = {}; this.database = database; this.namespace = 'firebase:db:ref'; this.query = new Query(this, path, existingModifiers); @@ -280,13 +280,13 @@ export default class Reference extends ReferenceBase { } const listener = { - listenerId: Object.keys(this.listeners).length + 1, + listenerId: Object.keys(this.refListeners).length + 1, eventName: eventType, successCallback: _successCallback, failureCallback: _failureCallback, }; - this.listeners[listener.listenerId] = listener; + this.refListeners[listener.listenerId] = listener; this.database.on(this, listener); return successCallback; } @@ -342,7 +342,7 @@ export default class Reference extends ReferenceBase { off(eventType?: string = '', originalCallback?: () => any) { this.log.debug('ref.off(): ', this.refId, eventType); // $FlowFixMe - const listeners: Array = Object.values(this.listeners); + const listeners: Array = Object.values(this.refListeners); let listenersToRemove; if (eventType && originalCallback) { listenersToRemove = listeners.filter((listener) => { @@ -363,9 +363,9 @@ export default class Reference extends ReferenceBase { } // Remove the listeners from the reference to prevent memory leaks listenersToRemove.forEach((listener) => { - delete this.listeners[listener.listenerId]; + delete this.refListeners[listener.listenerId]; }); - return this.database.off(this.refId, listenersToRemove, Object.keys(this.listeners).length); + return this.database.off(this.refId, listenersToRemove, Object.keys(this.refListeners).length); } /**