Merge pull request #71 from Leeds-eBooks/patch/flow-errors-2
Fixed several flow errors
This commit is contained in:
commit
8a545439a4
|
@ -83,7 +83,12 @@ export default class Database extends Base {
|
||||||
* @param origCB
|
* @param origCB
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
off(refId: number, listeners: Array<DatabaseListener>, remainingListenersCount: number) {
|
off(
|
||||||
|
refId: number,
|
||||||
|
// $FlowFixMe
|
||||||
|
listeners: Array<DatabaseListener>,
|
||||||
|
remainingListenersCount: number
|
||||||
|
) {
|
||||||
this.log.debug('off() : ', refId, listeners);
|
this.log.debug('off() : ', refId, listeners);
|
||||||
|
|
||||||
// Delete the reference if there are no more listeners
|
// Delete the reference if there are no more listeners
|
||||||
|
|
|
@ -151,23 +151,25 @@ export default class Reference extends ReferenceBase {
|
||||||
*/
|
*/
|
||||||
off(eventName?: string = '', origCB?: () => any) {
|
off(eventName?: string = '', origCB?: () => any) {
|
||||||
this.log.debug('ref.off(): ', this.refId, eventName);
|
this.log.debug('ref.off(): ', this.refId, eventName);
|
||||||
|
// $FlowFixMe
|
||||||
|
const listeners: Array<DatabaseListener> = Object.values(this.listeners);
|
||||||
let listenersToRemove;
|
let listenersToRemove;
|
||||||
if (eventName && origCB) {
|
if (eventName && origCB) {
|
||||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
listenersToRemove = listeners.filter((listener) => {
|
||||||
return listener.eventName === eventName && listener.successCallback === origCB;
|
return listener.eventName === eventName && listener.successCallback === origCB;
|
||||||
});
|
});
|
||||||
// Only remove a single listener as per the web spec
|
// Only remove a single listener as per the web spec
|
||||||
if (listenersToRemove.length > 1) listenersToRemove = [listenersToRemove[0]];
|
if (listenersToRemove.length > 1) listenersToRemove = [listenersToRemove[0]];
|
||||||
} else if (eventName) {
|
} else if (eventName) {
|
||||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
listenersToRemove = listeners.filter((listener) => {
|
||||||
return listener.eventName === eventName;
|
return listener.eventName === eventName;
|
||||||
});
|
});
|
||||||
} else if (origCB) {
|
} else if (origCB) {
|
||||||
listenersToRemove = Object.values(this.listeners).filter((listener) => {
|
listenersToRemove = listeners.filter((listener) => {
|
||||||
return listener.successCallback === origCB;
|
return listener.successCallback === origCB;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
listenersToRemove = Object.values(this.listeners);
|
listenersToRemove = listeners;
|
||||||
}
|
}
|
||||||
// Remove the listeners from the reference to prevent memory leaks
|
// Remove the listeners from the reference to prevent memory leaks
|
||||||
listenersToRemove.forEach((listener) => {
|
listenersToRemove.forEach((listener) => {
|
||||||
|
@ -183,7 +185,7 @@ export default class Reference extends ReferenceBase {
|
||||||
* @param onComplete
|
* @param onComplete
|
||||||
* @param applyLocally
|
* @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.'));
|
if (!isFunction(transactionUpdate)) return Promise.reject(new Error('Missing transactionUpdate function argument.'));
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
@ -80,7 +80,7 @@ export default class StorageReference extends ReferenceBase {
|
||||||
* Alias to putFile
|
* Alias to putFile
|
||||||
* @returns {StorageReference.putFile}
|
* @returns {StorageReference.putFile}
|
||||||
*/
|
*/
|
||||||
get put() {
|
get put(): Function {
|
||||||
return this.putFile;
|
return this.putFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,13 @@ declare type UploadTaskSnapshotType = {
|
||||||
downloadURL: string|null,
|
downloadURL: string|null,
|
||||||
metadata: Object, // TODO flow type def for https://firebase.google.com/docs/reference/js/firebase.storage.FullMetadata.html
|
metadata: Object, // TODO flow type def for https://firebase.google.com/docs/reference/js/firebase.storage.FullMetadata.html
|
||||||
ref: StorageReference,
|
ref: StorageReference,
|
||||||
state: StorageStatics.TaskState.RUNNING
|
state: (
|
||||||
|StorageStatics.TaskState.PAUSED
|
typeof StorageStatics.TaskState.RUNNING
|
||||||
|StorageStatics.TaskState.SUCCESS
|
| typeof StorageStatics.TaskState.PAUSED
|
||||||
|StorageStatics.TaskState.CANCELLED
|
| typeof StorageStatics.TaskState.SUCCESS
|
||||||
|StorageStatics.TaskState.ERROR,
|
| typeof StorageStatics.TaskState.CANCELLED
|
||||||
|
| typeof StorageStatics.TaskState.ERROR
|
||||||
|
),
|
||||||
task: StorageTask,
|
task: StorageTask,
|
||||||
totalBytes: number,
|
totalBytes: number,
|
||||||
};
|
};
|
||||||
|
@ -24,15 +26,26 @@ declare type FuncSnapshotType = null|(snapshot: UploadTaskSnapshotType) => any;
|
||||||
|
|
||||||
declare type FuncErrorType = null|(error: Error) => any;
|
declare type FuncErrorType = null|(error: Error) => any;
|
||||||
|
|
||||||
declare type NextOrObserverType = null
|
declare type NextOrObserverType = null |
|
||||||
|{ next?: FuncSnapshotType, error?: FuncErrorType, complete?:FuncSnapshotType }
|
{
|
||||||
|FuncSnapshotType;
|
next?: FuncSnapshotType,
|
||||||
|
error?: FuncErrorType,
|
||||||
|
complete?:FuncSnapshotType
|
||||||
|
} |
|
||||||
|
FuncSnapshotType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @url https://firebase.google.com/docs/reference/js/firebase.storage.UploadTask
|
* @url https://firebase.google.com/docs/reference/js/firebase.storage.UploadTask
|
||||||
*/
|
*/
|
||||||
export default class StorageTask {
|
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.type = type;
|
||||||
this.ref = storageRef;
|
this.ref = storageRef;
|
||||||
this.storage = storageRef.storage;
|
this.storage = storageRef.storage;
|
||||||
|
@ -49,13 +62,13 @@ export default class StorageTask {
|
||||||
* @returns {Promise.<T>}
|
* @returns {Promise.<T>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_interceptSnapshotEvent(f: Function|null|undefined): null|() => any {
|
_interceptSnapshotEvent(f: ?Function): null | () => * {
|
||||||
if (!isFunction(f)) return null;
|
if (!isFunction(f)) return null;
|
||||||
return (snapshot) => {
|
return (snapshot) => {
|
||||||
const _snapshot = Object.assign({}, snapshot);
|
const _snapshot = Object.assign({}, snapshot);
|
||||||
_snapshot.task = this;
|
_snapshot.task = this;
|
||||||
_snapshot.ref = this.ref;
|
_snapshot.ref = this.ref;
|
||||||
return f(_snapshot);
|
return f && f(_snapshot);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +78,13 @@ export default class StorageTask {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_interceptErrorEvent(f: Function|null|undefined): null|() => any {
|
_interceptErrorEvent(f: ?Function): null | (Error) => * {
|
||||||
if (!isFunction(f)) return null;
|
if (!isFunction(f)) return null;
|
||||||
return (error) => {
|
return (error) => {
|
||||||
const _error = new Error(error.message);
|
const _error = new Error(error.message);
|
||||||
|
// $FlowFixMe
|
||||||
_error.code = error.code;
|
_error.code = error.code;
|
||||||
return f(_error);
|
return f && f(_error);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,15 +97,41 @@ export default class StorageTask {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_subscribe(nextOrObserver: NextOrObserverType, error: FuncErrorType, complete: FuncSnapshotType): Function {
|
_subscribe(nextOrObserver: NextOrObserverType, error: FuncErrorType, complete: FuncSnapshotType): Function {
|
||||||
const observer = isObject(nextOrObserver);
|
let _error;
|
||||||
|
let _next;
|
||||||
|
let _complete;
|
||||||
|
|
||||||
const _error = this._interceptErrorEvent(observer ? nextOrObserver.error : error);
|
if (typeof nextOrObserver === 'function') {
|
||||||
const _next = this._interceptSnapshotEvent(observer ? nextOrObserver.next : nextOrObserver);
|
_error = this._interceptErrorEvent(error);
|
||||||
const _complete = this._interceptSnapshotEvent(observer ? nextOrObserver.complete : complete);
|
_next = this._interceptSnapshotEvent(nextOrObserver);
|
||||||
|
_complete = this._interceptSnapshotEvent(complete);
|
||||||
|
} else if (nextOrObserver) {
|
||||||
|
_error = this._interceptErrorEvent(nextOrObserver.error);
|
||||||
|
_next = this._interceptSnapshotEvent(nextOrObserver.next);
|
||||||
|
_complete = this._interceptSnapshotEvent(nextOrObserver.complete);
|
||||||
|
}
|
||||||
|
|
||||||
if (_next) this.storage._addListener(this.path, StorageStatics.TaskEvent.STATE_CHANGED, _next);
|
if (_next) {
|
||||||
if (_error) this.storage._addListener(this.path, `${this.type}_failure`, _error);
|
this.storage._addListener(
|
||||||
if (_complete) this.storage._addListener(this.path, `${this.type}_success`, _complete);
|
this.path,
|
||||||
|
StorageStatics.TaskEvent.STATE_CHANGED,
|
||||||
|
_next
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (_error) {
|
||||||
|
this.storage._addListener(
|
||||||
|
this.path,
|
||||||
|
`${this.type}_failure`,
|
||||||
|
_error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (_complete) {
|
||||||
|
this.storage._addListener(
|
||||||
|
this.path,
|
||||||
|
`${this.type}_success`,
|
||||||
|
_complete
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (_next) this.storage._removeListener(this.path, StorageStatics.TaskEvent.STATE_CHANGED, _next);
|
if (_next) this.storage._removeListener(this.path, StorageStatics.TaskEvent.STATE_CHANGED, _next);
|
||||||
|
|
|
@ -25,7 +25,7 @@ class CoreContainer extends React.Component {
|
||||||
StatusBar.setBackgroundColor('#0279ba');
|
StatusBar.setBackgroundColor('#0279ba');
|
||||||
}
|
}
|
||||||
if (Platform.OS === 'ios') {
|
if (Platform.OS === 'ios') {
|
||||||
StatusBar.setBarStyle('light-content')
|
StatusBar.setBarStyle('light-content');
|
||||||
}
|
}
|
||||||
AppState.addEventListener('change', this.handleAppStateChange);
|
AppState.addEventListener('change', this.handleAppStateChange);
|
||||||
NetInfo.isConnected.fetch().then((isConnected) => {
|
NetInfo.isConnected.fetch().then((isConnected) => {
|
||||||
|
@ -44,6 +44,7 @@ class CoreContainer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
props: Props;
|
props: Props;
|
||||||
|
_isConnected: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle app state changes
|
* Handle app state changes
|
||||||
|
|
Loading…
Reference in New Issue