mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
initial commit: basic flow errors
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
// modeled after base64 web-safe chars, but ordered by ASCII
|
||||
const PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
|
||||
const hasOwnProperty = Object.hasOwnProperty;
|
||||
@@ -8,7 +11,8 @@ const _handler = (resolve, reject, errorPrefix, err, resp) => {
|
||||
// resolve / reject after events etc
|
||||
setImmediate(() => {
|
||||
if (err) {
|
||||
const firebaseError = new Error(err.message);
|
||||
// $FlowFixMe
|
||||
const firebaseError: FirebaseError = new Error(err.message);
|
||||
|
||||
if (isObject(err)) {
|
||||
Object.keys(err).forEach(key => Object.defineProperty(firebaseError, key, { value: err[key] }));
|
||||
@@ -23,7 +27,7 @@ const _handler = (resolve, reject, errorPrefix, err, resp) => {
|
||||
});
|
||||
};
|
||||
|
||||
export function toWebSDKErrorCode(code, prefix) {
|
||||
export function toWebSDKErrorCode(code: any, prefix: string): string {
|
||||
if (!code || typeof code !== 'string') return '';
|
||||
return code.toLowerCase().replace('error_', prefix).replace(/_/g, '-');
|
||||
}
|
||||
@@ -36,7 +40,11 @@ export function toWebSDKErrorCode(code, prefix) {
|
||||
* @param joiner
|
||||
* @returns {*}
|
||||
*/
|
||||
export function deepGet(object, path, joiner = '/') {
|
||||
export function deepGet(
|
||||
object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'
|
||||
): any {
|
||||
const keys = path.split(joiner);
|
||||
|
||||
let i = 0;
|
||||
@@ -60,7 +68,11 @@ export function deepGet(object, path, joiner = '/') {
|
||||
* @param joiner
|
||||
* @returns {*}
|
||||
*/
|
||||
export function deepExists(object, path, joiner = '/') {
|
||||
export function deepExists(
|
||||
object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'
|
||||
): boolean {
|
||||
const keys = path.split(joiner);
|
||||
|
||||
let i = 0;
|
||||
@@ -81,7 +93,7 @@ export function deepExists(object, path, joiner = '/') {
|
||||
* @param item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isObject(item) {
|
||||
export function isObject(item: any): boolean {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
|
||||
}
|
||||
|
||||
@@ -90,8 +102,8 @@ export function isObject(item) {
|
||||
* @param item
|
||||
* @returns {*|boolean}
|
||||
*/
|
||||
export function isFunction(item) {
|
||||
return (item && typeof item === 'function');
|
||||
export function isFunction(item?: any): boolean {
|
||||
return Boolean(item && typeof item === 'function');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +124,7 @@ export function tryJSONParse(string) {
|
||||
* @param data
|
||||
* @returns {*}
|
||||
*/
|
||||
export function tryJSONStringify(data) {
|
||||
export function tryJSONStringify(data: any): string | null {
|
||||
try {
|
||||
return JSON.stringify(data);
|
||||
} catch (jsonError) {
|
||||
@@ -149,7 +161,11 @@ export function noop(): void {
|
||||
* @param NativeModule
|
||||
* @param errorPrefix
|
||||
*/
|
||||
export function promisify(fn: Function, NativeModule: Object, errorPrefix): Function<Promise> {
|
||||
export function promisify(
|
||||
fn: Function | string,
|
||||
NativeModule: Object,
|
||||
errorPrefix?: string
|
||||
): (any) => Promise<> {
|
||||
return (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const _fn = typeof fn === 'function' ? fn : NativeModule[fn];
|
||||
@@ -168,7 +184,12 @@ export function promisify(fn: Function, NativeModule: Object, errorPrefix): Func
|
||||
* @param callback
|
||||
* @private
|
||||
*/
|
||||
function _delayChunk(collection, chunkSize, operation, callback): void {
|
||||
function _delayChunk(
|
||||
collection: Array<*>,
|
||||
chunkSize: number,
|
||||
operation: Function,
|
||||
callback: Function
|
||||
): void {
|
||||
const length = collection.length;
|
||||
const iterations = Math.ceil(length / chunkSize);
|
||||
|
||||
@@ -210,7 +231,7 @@ export function each(array: Array, chunkSize?: number, iterator: Function, cb: F
|
||||
}, cb);
|
||||
}
|
||||
|
||||
export function typeOf(value) {
|
||||
export function typeOf(value: any): string {
|
||||
if (value === null) return 'null';
|
||||
if (Array.isArray(value)) return 'array';
|
||||
return typeof value;
|
||||
|
||||
Reference in New Issue
Block a user