2
0
mirror of synced 2025-01-11 22:54:12 +00:00

flow fixes that change logic slightly

This commit is contained in:
Ben Styles 2017-04-04 17:58:47 +01:00
parent 5acea6d218
commit 51a07fc4ee
2 changed files with 24 additions and 12 deletions

View File

@ -50,7 +50,7 @@ export default class TransactionHandler extends Base {
started: true, started: true,
}; };
FirebaseDatabase.startTransaction(reference.path, id, applyLocally || false); FirebaseDatabase.startTransaction(reference.path, id, applyLocally);
} }
/** /**
@ -77,7 +77,7 @@ export default class TransactionHandler extends Base {
case 'update': case 'update':
return this._handleUpdate(event); return this._handleUpdate(event);
case 'error': case 'error':
return this._handleError(error); return this._handleError(event);
case 'complete': case 'complete':
return this._handleComplete(event); return this._handleComplete(event);
default: default:

View File

@ -111,9 +111,9 @@ export function isFunction(item?: any): boolean {
* @param string * @param string
* @returns {*} * @returns {*}
*/ */
export function tryJSONParse(string) { export function tryJSONParse(string: string | null): any {
try { try {
return JSON.parse(string); return string && JSON.parse(string);
} catch (jsonError) { } catch (jsonError) {
return string; return string;
} }
@ -217,18 +217,25 @@ function _delayChunk(
* @param iterator * @param iterator
* @param cb * @param cb
*/ */
export function each(array: Array, chunkSize?: number, iterator: Function, cb: Function): void { export function each(
array: Array<*>,
chunkSize: number | Function,
iterator: Function,
cb?: Function
): void {
if (typeof chunkSize === 'function') { if (typeof chunkSize === 'function') {
cb = iterator; cb = iterator;
iterator = chunkSize; iterator = chunkSize;
chunkSize = DEFAULT_CHUNK_SIZE; chunkSize = DEFAULT_CHUNK_SIZE;
} }
if (cb) {
_delayChunk(array, chunkSize, (slice, start) => { _delayChunk(array, chunkSize, (slice, start) => {
for (let ii = 0, jj = slice.length; ii < jj; ii += 1) { for (let ii = 0, jj = slice.length; ii < jj; ii += 1) {
iterator(slice[ii], start + ii); iterator(slice[ii], start + ii);
} }
}, cb); }, cb);
}
} }
export function typeOf(value: any): string { export function typeOf(value: any): string {
@ -245,7 +252,12 @@ export function typeOf(value: any): string {
* @param cb * @param cb
* @returns {*} * @returns {*}
*/ */
export function map(array: Array, chunkSize?: number, iterator: Function, cb: Function): void { export function map(
array: Array<*>,
chunkSize: number | Function,
iterator: Function,
cb?: Function
): void {
if (typeof chunkSize === 'function') { if (typeof chunkSize === 'function') {
cb = iterator; cb = iterator;
iterator = chunkSize; iterator = chunkSize;
@ -258,7 +270,7 @@ export function map(array: Array, chunkSize?: number, iterator: Function, cb: Fu
result.push(iterator(slice[ii], start + ii, array)); result.push(iterator(slice[ii], start + ii, array));
} }
return result; return result;
}, () => cb(result)); }, () => cb && cb(result));
} }