mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-22 11:16:18 +08:00
[js] Run prettier for the first time
This commit is contained in:
@@ -8,7 +8,7 @@ import DatabaseSnapshot from '../modules/database/snapshot';
|
||||
import DatabaseReference from '../modules/database/reference';
|
||||
import { isString, nativeToJSError } from '../utils';
|
||||
|
||||
type Listener = (DatabaseSnapshot) => any;
|
||||
type Listener = DatabaseSnapshot => any;
|
||||
|
||||
type Registration = {
|
||||
key: string,
|
||||
@@ -19,7 +19,7 @@ type Registration = {
|
||||
listener: Listener,
|
||||
eventRegistrationKey: string,
|
||||
ref: DatabaseReference,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Internally used to manage firebase database realtime event
|
||||
@@ -28,16 +28,18 @@ type Registration = {
|
||||
class SyncTree {
|
||||
_nativeEmitter: NativeEventEmitter;
|
||||
_reverseLookup: { [string]: Registration };
|
||||
_tree: { [string]: { [string]: { [string]: Listener }}};
|
||||
_tree: { [string]: { [string]: { [string]: Listener } } };
|
||||
|
||||
constructor() {
|
||||
this._tree = {};
|
||||
this._reverseLookup = {};
|
||||
if (NativeModules.RNFirebaseDatabase) {
|
||||
this._nativeEmitter = new NativeEventEmitter(NativeModules.RNFirebaseDatabase);
|
||||
this._nativeEmitter = new NativeEventEmitter(
|
||||
NativeModules.RNFirebaseDatabase
|
||||
);
|
||||
this._nativeEmitter.addListener(
|
||||
'database_sync_event',
|
||||
this._handleSyncEvent.bind(this),
|
||||
this._handleSyncEvent.bind(this)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -82,11 +84,10 @@ class SyncTree {
|
||||
return SharedEventEmitter.emit(
|
||||
eventRegistrationKey,
|
||||
new DatabaseSnapshot(registration.ref, snapshot),
|
||||
previousChildName,
|
||||
previousChildName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Routes native database query listener cancellation events to their js counterparts.
|
||||
*
|
||||
@@ -96,7 +97,10 @@ class SyncTree {
|
||||
_handleErrorEvent(event) {
|
||||
// console.log('SyncTree.ERROR >>>', event);
|
||||
const { code, message } = event.error;
|
||||
const { eventRegistrationKey, registrationCancellationKey } = event.registration;
|
||||
const {
|
||||
eventRegistrationKey,
|
||||
registrationCancellationKey,
|
||||
} = event.registration;
|
||||
|
||||
const registration = this.getRegistration(registrationCancellationKey);
|
||||
|
||||
@@ -121,7 +125,9 @@ class SyncTree {
|
||||
* @return {null}
|
||||
*/
|
||||
getRegistration(registration: string): Registration | null {
|
||||
return this._reverseLookup[registration] ? Object.assign({}, this._reverseLookup[registration]) : null;
|
||||
return this._reverseLookup[registration]
|
||||
? Object.assign({}, this._reverseLookup[registration])
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +165,9 @@ class SyncTree {
|
||||
|
||||
for (let i = 0, len = registrations.length; i < len; i++) {
|
||||
const registration = registrations[i];
|
||||
const subscriptions = SharedEventEmitter._subscriber.getSubscriptionsForType(registration);
|
||||
const subscriptions = SharedEventEmitter._subscriber.getSubscriptionsForType(
|
||||
registration
|
||||
);
|
||||
if (subscriptions) {
|
||||
for (let j = 0, l = subscriptions.length; j < l; j++) {
|
||||
const subscription = subscriptions[j];
|
||||
@@ -188,7 +196,10 @@ class SyncTree {
|
||||
const eventKeys = Object.keys(this._tree[path] || {});
|
||||
|
||||
for (let i = 0, len = eventKeys.length; i < len; i++) {
|
||||
Array.prototype.push.apply(out, Object.keys(this._tree[path][eventKeys[i]]));
|
||||
Array.prototype.push.apply(
|
||||
out,
|
||||
Object.keys(this._tree[path][eventKeys[i]])
|
||||
);
|
||||
}
|
||||
|
||||
return out;
|
||||
@@ -216,11 +227,17 @@ class SyncTree {
|
||||
* @param listener
|
||||
* @return {Array}
|
||||
*/
|
||||
getOneByPathEventListener(path: string, eventType: string, listener: Function): ?string {
|
||||
getOneByPathEventListener(
|
||||
path: string,
|
||||
eventType: string,
|
||||
listener: Function
|
||||
): ?string {
|
||||
if (!this._tree[path]) return null;
|
||||
if (!this._tree[path][eventType]) return null;
|
||||
|
||||
const registrationsForPathEvent = Object.entries(this._tree[path][eventType]);
|
||||
const registrationsForPathEvent = Object.entries(
|
||||
this._tree[path][eventType]
|
||||
);
|
||||
|
||||
for (let i = 0; i < registrationsForPathEvent.length; i++) {
|
||||
const registration = registrationsForPathEvent[i];
|
||||
@@ -230,7 +247,6 @@ class SyncTree {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a new listener.
|
||||
*
|
||||
@@ -256,7 +272,7 @@ class SyncTree {
|
||||
if (once) {
|
||||
SharedEventEmitter.once(
|
||||
eventRegistrationKey,
|
||||
this._onOnceRemoveRegistration(eventRegistrationKey, listener),
|
||||
this._onOnceRemoveRegistration(eventRegistrationKey, listener)
|
||||
);
|
||||
} else {
|
||||
SharedEventEmitter.addListener(eventRegistrationKey, listener);
|
||||
|
||||
Reference in New Issue
Block a user