mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-21 10:34:39 +08:00
[types] Get flow type working again; Fix majority of firestore type issues
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
import { NativeEventEmitter } from 'react-native';
|
||||
|
||||
import INTERNALS from './../internals';
|
||||
@@ -6,13 +9,13 @@ import DatabaseReference from './../modules/database/reference';
|
||||
import { isString, nativeToJSError } from './../utils';
|
||||
|
||||
type Registration = {
|
||||
key: String,
|
||||
path: String,
|
||||
once?: Boolean,
|
||||
appName: String,
|
||||
eventType: String,
|
||||
key: string,
|
||||
path: string,
|
||||
once?: boolean,
|
||||
appName: string,
|
||||
eventType: string,
|
||||
listener: Function,
|
||||
eventRegistrationKey: String,
|
||||
eventRegistrationKey: string,
|
||||
ref: DatabaseReference,
|
||||
}
|
||||
|
||||
@@ -21,7 +24,12 @@ type Registration = {
|
||||
* subscriptions and keep the listeners in sync in js vs native.
|
||||
*/
|
||||
export default class SyncTree {
|
||||
constructor(databaseNative) {
|
||||
_databaseNative: Object;
|
||||
_nativeEmitter: NativeEventEmitter;
|
||||
_reverseLookup: { [string]: Registration };
|
||||
_tree: { [string]: { [string]: Array }};
|
||||
|
||||
constructor(databaseNative: Object) {
|
||||
this._tree = {};
|
||||
this._reverseLookup = {};
|
||||
this._databaseNative = databaseNative;
|
||||
@@ -110,7 +118,7 @@ export default class SyncTree {
|
||||
* @param registration
|
||||
* @return {null}
|
||||
*/
|
||||
getRegistration(registration): Registration | null {
|
||||
getRegistration(registration: string): Registration | null {
|
||||
return this._reverseLookup[registration] ? Object.assign({}, this._reverseLookup[registration]) : null;
|
||||
}
|
||||
|
||||
@@ -120,7 +128,7 @@ export default class SyncTree {
|
||||
* @param registrations
|
||||
* @return {number}
|
||||
*/
|
||||
removeListenersForRegistrations(registrations) {
|
||||
removeListenersForRegistrations(registrations: string | string[]) {
|
||||
if (isString(registrations)) {
|
||||
this.removeRegistration(registrations);
|
||||
INTERNALS.SharedEventEmitter.removeAllListeners(registrations);
|
||||
@@ -143,7 +151,7 @@ export default class SyncTree {
|
||||
* @param registrations
|
||||
* @return {Array} array of registrations removed
|
||||
*/
|
||||
removeListenerRegistrations(listener, registrations) {
|
||||
removeListenerRegistrations(listener, registrations: string[]) {
|
||||
if (!Array.isArray(registrations)) return [];
|
||||
const removed = [];
|
||||
|
||||
@@ -173,7 +181,7 @@ export default class SyncTree {
|
||||
* @param path
|
||||
* @return {Array}
|
||||
*/
|
||||
getRegistrationsByPath(path): Array {
|
||||
getRegistrationsByPath(path: string): Array {
|
||||
const out = [];
|
||||
const eventKeys = Object.keys(this._tree[path] || {});
|
||||
|
||||
@@ -191,7 +199,7 @@ export default class SyncTree {
|
||||
* @param eventType
|
||||
* @return {Array}
|
||||
*/
|
||||
getRegistrationsByPathEvent(path, eventType): Array {
|
||||
getRegistrationsByPathEvent(path: string, eventType: string): Array {
|
||||
if (!this._tree[path]) return [];
|
||||
if (!this._tree[path][eventType]) return [];
|
||||
|
||||
@@ -228,8 +236,13 @@ export default class SyncTree {
|
||||
* @param listener
|
||||
* @return {String}
|
||||
*/
|
||||
addRegistration(parameters: Registration, listener): String {
|
||||
const { path, eventType, eventRegistrationKey, once } = parameters;
|
||||
addRegistration(parameters: Registration, listener: Function): string {
|
||||
const {
|
||||
path,
|
||||
eventType,
|
||||
eventRegistrationKey,
|
||||
once,
|
||||
} = parameters;
|
||||
|
||||
if (!this._tree[path]) this._tree[path] = {};
|
||||
if (!this._tree[path][eventType]) this._tree[path][eventType] = {};
|
||||
@@ -256,7 +269,7 @@ export default class SyncTree {
|
||||
* @param registration
|
||||
* @return {boolean}
|
||||
*/
|
||||
removeRegistration(registration: String): Boolean {
|
||||
removeRegistration(registration: string): boolean {
|
||||
if (!this._reverseLookup[registration]) return false;
|
||||
const { path, eventType, once } = this._reverseLookup[registration];
|
||||
|
||||
@@ -298,4 +311,3 @@ export default class SyncTree {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user