2
0
mirror of synced 2025-01-23 20:59:10 +00:00

[js][db] Rename .listeners

This commit is contained in:
Chris Bianca 2017-05-30 12:46:28 +01:00
parent ba24a80e09
commit b3cd102077
2 changed files with 12 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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<DatabaseModifier>) {
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<DatabaseListener> = Object.values(this.listeners);
const listeners: Array<DatabaseListener> = 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);
}
/**