fixed some flow and eslint errors
This commit is contained in:
parent
4fa51d2627
commit
6cee2609b1
|
@ -151,23 +151,25 @@ export default class Reference extends ReferenceBase {
|
|||
*/
|
||||
off(eventName?: string = '', origCB?: () => any) {
|
||||
this.log.debug('ref.off(): ', this.refId, eventName);
|
||||
// $FlowFixMe
|
||||
const listeners: Array<DatabaseListener> = Object.values(this.listeners);
|
||||
let listenersToRemove;
|
||||
if (eventName && origCB) {
|
||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
||||
listenersToRemove = listeners.filter((listener) => {
|
||||
return listener.eventName === eventName && listener.successCallback === origCB;
|
||||
});
|
||||
// Only remove a single listener as per the web spec
|
||||
if (listenersToRemove.length > 1) listenersToRemove = [listenersToRemove[0]];
|
||||
} else if (eventName) {
|
||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
||||
listenersToRemove = listeners.filter((listener) => {
|
||||
return listener.eventName === eventName;
|
||||
});
|
||||
} else if (origCB) {
|
||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
||||
listenersToRemove = listeners.filter((listener) => {
|
||||
return listener.successCallback === origCB;
|
||||
});
|
||||
} else {
|
||||
listenersToRemove = Object.values(this.listeners);
|
||||
listenersToRemove = listeners;
|
||||
}
|
||||
// Remove the listeners from the reference to prevent memory leaks
|
||||
listenersToRemove.forEach((listener) => {
|
||||
|
@ -183,7 +185,7 @@ export default class Reference extends ReferenceBase {
|
|||
* @param onComplete
|
||||
* @param applyLocally
|
||||
*/
|
||||
transaction(transactionUpdate: Function, onComplete, applyLocally: boolean = false) {
|
||||
transaction(transactionUpdate: Function, onComplete: (?Error, boolean, ?Snapshot) => *, applyLocally: boolean = false) {
|
||||
if (!isFunction(transactionUpdate)) return Promise.reject(new Error('Missing transactionUpdate function argument.'));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -80,7 +80,7 @@ export default class StorageReference extends ReferenceBase {
|
|||
* Alias to putFile
|
||||
* @returns {StorageReference.putFile}
|
||||
*/
|
||||
get put() {
|
||||
get put(): Function {
|
||||
return this.putFile;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,13 @@ declare type UploadTaskSnapshotType = {
|
|||
downloadURL: string|null,
|
||||
metadata: Object, // TODO flow type def for https://firebase.google.com/docs/reference/js/firebase.storage.FullMetadata.html
|
||||
ref: StorageReference,
|
||||
state: StorageStatics.TaskState.RUNNING
|
||||
|StorageStatics.TaskState.PAUSED
|
||||
|StorageStatics.TaskState.SUCCESS
|
||||
|StorageStatics.TaskState.CANCELLED
|
||||
|StorageStatics.TaskState.ERROR,
|
||||
state: (
|
||||
typeof StorageStatics.TaskState.RUNNING
|
||||
| typeof StorageStatics.TaskState.PAUSED
|
||||
| typeof StorageStatics.TaskState.SUCCESS
|
||||
| typeof StorageStatics.TaskState.CANCELLED
|
||||
| typeof StorageStatics.TaskState.ERROR
|
||||
),
|
||||
task: StorageTask,
|
||||
totalBytes: number,
|
||||
};
|
||||
|
@ -32,7 +34,14 @@ declare type NextOrObserverType = null
|
|||
* @url https://firebase.google.com/docs/reference/js/firebase.storage.UploadTask
|
||||
*/
|
||||
export default class StorageTask {
|
||||
constructor(type: UPLOAD_TASK|DOWNLOAD_TASK, promise: Promise, storageRef: StorageReference) {
|
||||
type: typeof UPLOAD_TASK | typeof DOWNLOAD_TASK
|
||||
ref: StorageReference
|
||||
storage: StorageReference.storage
|
||||
path: StorageReference.path
|
||||
then: Promise<*>
|
||||
catch: () => Promise<*>
|
||||
|
||||
constructor(type: typeof UPLOAD_TASK | typeof DOWNLOAD_TASK, promise: Promise<*>, storageRef: StorageReference) {
|
||||
this.type = type;
|
||||
this.ref = storageRef;
|
||||
this.storage = storageRef.storage;
|
||||
|
@ -49,13 +58,13 @@ export default class StorageTask {
|
|||
* @returns {Promise.<T>}
|
||||
* @private
|
||||
*/
|
||||
_interceptSnapshotEvent(f: Function|null|undefined): null|() => any {
|
||||
_interceptSnapshotEvent(f: ?Function): null | () => * {
|
||||
if (!isFunction(f)) return null;
|
||||
return (snapshot) => {
|
||||
const _snapshot = Object.assign({}, snapshot);
|
||||
_snapshot.task = this;
|
||||
_snapshot.ref = this.ref;
|
||||
return f(_snapshot);
|
||||
return f && f(_snapshot);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -65,12 +74,13 @@ export default class StorageTask {
|
|||
* @returns {*}
|
||||
* @private
|
||||
*/
|
||||
_interceptErrorEvent(f: Function|null|undefined): null|() => any {
|
||||
_interceptErrorEvent(f: ?Function): null | (Error) => * {
|
||||
if (!isFunction(f)) return null;
|
||||
return (error) => {
|
||||
const _error = new Error(error.message);
|
||||
// $FlowFixMe
|
||||
_error.code = error.code;
|
||||
return f(_error);
|
||||
return f && f(_error);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class CoreContainer extends React.Component {
|
|||
StatusBar.setBackgroundColor('#0279ba');
|
||||
}
|
||||
if (Platform.OS === 'ios') {
|
||||
StatusBar.setBarStyle('light-content')
|
||||
StatusBar.setBarStyle('light-content');
|
||||
}
|
||||
AppState.addEventListener('change', this.handleAppStateChange);
|
||||
NetInfo.isConnected.fetch().then((isConnected) => {
|
||||
|
@ -44,6 +44,7 @@ class CoreContainer extends React.Component {
|
|||
}
|
||||
|
||||
props: Props;
|
||||
_isConnected: boolean;
|
||||
|
||||
/**
|
||||
* Handle app state changes
|
||||
|
|
Loading…
Reference in New Issue