misc cleanup of redundant code + flow type fixes
This commit is contained in:
parent
72d27f5680
commit
b53bf5bbe8
|
@ -6,6 +6,8 @@ export default class PerformanceMonitoring extends ModuleBase {
|
||||||
static _NAMESPACE = 'perf';
|
static _NAMESPACE = 'perf';
|
||||||
static _NATIVE_MODULE = 'RNFirebasePerformance';
|
static _NATIVE_MODULE = 'RNFirebasePerformance';
|
||||||
|
|
||||||
|
_native: Object;
|
||||||
|
|
||||||
constructor(firebaseApp: Object, options: Object = {}) {
|
constructor(firebaseApp: Object, options: Object = {}) {
|
||||||
super(firebaseApp, options);
|
super(firebaseApp, options);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +28,4 @@ export default class PerformanceMonitoring extends ModuleBase {
|
||||||
newTrace(trace: string): void {
|
newTrace(trace: string): void {
|
||||||
return new Trace(this, trace);
|
return new Trace(this, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
get namespace(): string {
|
|
||||||
return 'firebase:perf';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import { Platform } from 'react-native';
|
||||||
// modeled after base64 web-safe chars, but ordered by ASCII
|
// modeled after base64 web-safe chars, but ordered by ASCII
|
||||||
const PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
|
const PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
|
||||||
const hasOwnProperty = Object.hasOwnProperty;
|
const hasOwnProperty = Object.hasOwnProperty;
|
||||||
const DEFAULT_CHUNK_SIZE = 50;
|
|
||||||
|
// const DEFAULT_CHUNK_SIZE = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deep get a value from an object.
|
* Deep get a value from an object.
|
||||||
|
@ -129,63 +130,63 @@ export function noop(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Delays chunks based on sizes per event loop.
|
// * Delays chunks based on sizes per event loop.
|
||||||
* @param collection
|
// * @param collection
|
||||||
* @param chunkSize
|
// * @param chunkSize
|
||||||
* @param operation
|
// * @param operation
|
||||||
* @param callback
|
// * @param callback
|
||||||
* @private
|
// * @private
|
||||||
*/
|
// */
|
||||||
function _delayChunk(collection: Array<*>,
|
// function _delayChunk(collection: Array<*>,
|
||||||
chunkSize: number,
|
// chunkSize: number,
|
||||||
operation: Function,
|
// operation: Function,
|
||||||
callback: Function): void {
|
// callback: Function): void {
|
||||||
const length = collection.length;
|
// const length = collection.length;
|
||||||
const iterations = Math.ceil(length / chunkSize);
|
// const iterations = Math.ceil(length / chunkSize);
|
||||||
|
//
|
||||||
// noinspection ES6ConvertVarToLetConst
|
// // noinspection ES6ConvertVarToLetConst
|
||||||
let thisIteration = 0;
|
// let thisIteration = 0;
|
||||||
|
//
|
||||||
setImmediate(function next() {
|
// setImmediate(function next() {
|
||||||
const start = thisIteration * chunkSize;
|
// const start = thisIteration * chunkSize;
|
||||||
const _end = start + chunkSize;
|
// const _end = start + chunkSize;
|
||||||
const end = _end >= length ? length : _end;
|
// const end = _end >= length ? length : _end;
|
||||||
const result = operation(collection.slice(start, end), start, end);
|
// const result = operation(collection.slice(start, end), start, end);
|
||||||
|
//
|
||||||
if (thisIteration++ > iterations) {
|
// if (thisIteration++ > iterations) {
|
||||||
callback(null, result);
|
// callback(null, result);
|
||||||
} else {
|
// } else {
|
||||||
setImmediate(next);
|
// setImmediate(next);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Async each with optional chunk size limit
|
// * Async each with optional chunk size limit
|
||||||
* @param array
|
// * @param array
|
||||||
* @param chunkSize
|
// * @param chunkSize
|
||||||
* @param iterator
|
// * @param iterator
|
||||||
* @param cb
|
// * @param cb
|
||||||
*/
|
// */
|
||||||
export function each(array: Array<*>,
|
// export function each(array: Array<*>,
|
||||||
chunkSize: number | Function,
|
// chunkSize: number | Function,
|
||||||
iterator: Function,
|
// iterator: Function,
|
||||||
cb?: Function): void {
|
// 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) {
|
// 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);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string typeof that's valid for Firebase usage
|
* Returns a string typeof that's valid for Firebase usage
|
||||||
|
@ -198,41 +199,41 @@ export function typeOf(value: any): string {
|
||||||
return typeof value;
|
return typeof value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Async map with optional chunk size limit
|
// * Async map with optional chunk size limit
|
||||||
* @param array
|
// * @param array
|
||||||
* @param chunkSize
|
// * @param chunkSize
|
||||||
* @param iterator
|
// * @param iterator
|
||||||
* @param cb
|
// * @param cb
|
||||||
* @returns {*}
|
// * @returns {*}
|
||||||
*/
|
// */
|
||||||
export function map(array: Array<*>,
|
// export function map(array: Array<*>,
|
||||||
chunkSize: number | Function,
|
// chunkSize: number | Function,
|
||||||
iterator: Function,
|
// iterator: Function,
|
||||||
cb?: Function): void {
|
// 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;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// const result = [];
|
||||||
|
// _delayChunk(array, chunkSize, (slice, start) => {
|
||||||
|
// for (let ii = 0, jj = slice.length; ii < jj; ii += 1) {
|
||||||
|
// result.push(iterator(slice[ii], start + ii, array));
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }, () => cb && cb(result));
|
||||||
|
// }
|
||||||
|
|
||||||
const result = [];
|
// /**
|
||||||
_delayChunk(array, chunkSize, (slice, start) => {
|
// *
|
||||||
for (let ii = 0, jj = slice.length; ii < jj; ii += 1) {
|
// * @param string
|
||||||
result.push(iterator(slice[ii], start + ii, array));
|
// * @return {string}
|
||||||
}
|
// */
|
||||||
return result;
|
// export function capitalizeFirstLetter(string: String) {
|
||||||
}, () => cb && cb(result));
|
// return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
export function capitalizeFirstLetter(string: String) {
|
|
||||||
return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// timestamp of last push, used to prevent local collisions if you push twice in one ms.
|
// timestamp of last push, used to prevent local collisions if you push twice in one ms.
|
||||||
let lastPushTime = 0;
|
let lastPushTime = 0;
|
||||||
|
@ -296,7 +297,7 @@ export function generatePushID(serverTimeOffset?: number = 0): string {
|
||||||
* @returns {Error}
|
* @returns {Error}
|
||||||
*/
|
*/
|
||||||
export function nativeToJSError(code: string, message: string, additionalProps?: Object = {}) {
|
export function nativeToJSError(code: string, message: string, additionalProps?: Object = {}) {
|
||||||
const error = new Error(message);
|
const error: Object = new Error(message);
|
||||||
error.code = code;
|
error.code = code;
|
||||||
Object.assign(error, additionalProps);
|
Object.assign(error, additionalProps);
|
||||||
// exclude this function from the stack
|
// exclude this function from the stack
|
||||||
|
@ -310,7 +311,7 @@ export function nativeToJSError(code: string, message: string, additionalProps?:
|
||||||
* @param appName
|
* @param appName
|
||||||
* @param NativeModule
|
* @param NativeModule
|
||||||
*/
|
*/
|
||||||
export function nativeWithApp(appName, NativeModule) {
|
export function nativeWithApp(appName: string, NativeModule: Object) {
|
||||||
const native = {};
|
const native = {};
|
||||||
const methods = Object.keys(NativeModule);
|
const methods = Object.keys(NativeModule);
|
||||||
|
|
||||||
|
@ -329,7 +330,7 @@ export function nativeWithApp(appName, NativeModule) {
|
||||||
* @param object
|
* @param object
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
export function objectToUniqueId(object: Object): String {
|
export function objectToUniqueId(object: Object): string {
|
||||||
if (!isObject(object) || object === null) return JSON.stringify(object);
|
if (!isObject(object) || object === null) return JSON.stringify(object);
|
||||||
|
|
||||||
const keys = Object.keys(object).sort();
|
const keys = Object.keys(object).sort();
|
||||||
|
@ -355,7 +356,7 @@ export function objectToUniqueId(object: Object): String {
|
||||||
* @param optionalCallback
|
* @param optionalCallback
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
export function promiseOrCallback(promise: Promise, optionalCallback?: Function) {
|
export function promiseOrCallback(promise: Promise<*>, optionalCallback?: Function) {
|
||||||
if (!isFunction(optionalCallback)) return promise;
|
if (!isFunction(optionalCallback)) return promise;
|
||||||
|
|
||||||
return promise.then((result) => {
|
return promise.then((result) => {
|
||||||
|
|
Loading…
Reference in New Issue