mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
Fix for #532
This commit is contained in:
@@ -11,6 +11,7 @@ type Registration = {
|
||||
once?: Boolean,
|
||||
appName: String,
|
||||
eventType: String,
|
||||
listener: Function,
|
||||
eventRegistrationKey: String,
|
||||
ref: DatabaseReference,
|
||||
}
|
||||
@@ -197,6 +198,28 @@ export default class SyncTree {
|
||||
return Object.keys(this._tree[path][eventType]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single registration key for the specified path, eventType, and listener
|
||||
*
|
||||
* @param path
|
||||
* @param eventType
|
||||
* @param listener
|
||||
* @return {Array}
|
||||
*/
|
||||
getOneByPathEventListener(path: string, eventType: string, listener: Function): Array {
|
||||
if (!this._tree[path]) return [];
|
||||
if (!this._tree[path][eventType]) return [];
|
||||
|
||||
const registrationsForPathEvent = Object.entries(this._tree[path][eventType]);
|
||||
|
||||
for (let i = 0; i < registrationsForPathEvent.length; i++) {
|
||||
const registration = registrationsForPathEvent[i];
|
||||
if (registration[1] === listener) return registration[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a new listener.
|
||||
@@ -211,8 +234,8 @@ export default class SyncTree {
|
||||
if (!this._tree[path]) this._tree[path] = {};
|
||||
if (!this._tree[path][eventType]) this._tree[path][eventType] = {};
|
||||
|
||||
this._tree[path][eventType][eventRegistrationKey] = 0;
|
||||
this._reverseLookup[eventRegistrationKey] = Object.assign({}, parameters);
|
||||
this._tree[path][eventType][eventRegistrationKey] = listener;
|
||||
this._reverseLookup[eventRegistrationKey] = Object.assign({ listener }, parameters);
|
||||
|
||||
if (once) {
|
||||
INTERNALS.SharedEventEmitter.once(
|
||||
|
||||
Reference in New Issue
Block a user