[js][all] added nativeSDKMissing check for all modules - part of making all module native sdk's optional.
This commit is contained in:
parent
18e65b697f
commit
6f81605616
@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import { NativeModules } from 'react-native';
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
|
||||
const FirebaseAnalytics = NativeModules.RNFirebaseAnalytics;
|
||||
const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/;
|
||||
@ -21,7 +21,13 @@ const ReservedEventNames = [
|
||||
'user_engagement',
|
||||
];
|
||||
|
||||
export default class Analytics extends Base {
|
||||
export default class Analytics {
|
||||
constructor() {
|
||||
if (FirebaseAnalytics.nativeSDKMissing) {
|
||||
return nativeSDKMissing('analytics');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an app event.
|
||||
* @param {string} name
|
||||
|
@ -3,6 +3,7 @@ import { NativeModules, NativeEventEmitter } from 'react-native';
|
||||
|
||||
import User from './user';
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
|
||||
// providers
|
||||
import EmailAuthProvider from './providers/Email';
|
||||
@ -15,12 +16,16 @@ const FirebaseAuth = NativeModules.RNFirebaseAuth;
|
||||
const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth);
|
||||
|
||||
export default class Auth extends Base {
|
||||
_user: User|null;
|
||||
_user: User | null;
|
||||
_authResult: AuthResultType | null;
|
||||
authenticated: boolean;
|
||||
|
||||
constructor(firebase: Object, options: Object = {}) {
|
||||
super(firebase, options);
|
||||
if (FirebaseAuth.nativeSDKMissing) {
|
||||
return nativeSDKMissing('auth');
|
||||
}
|
||||
|
||||
this._user = null;
|
||||
this._authResult = null;
|
||||
this.authenticated = false;
|
||||
@ -168,7 +173,7 @@ export default class Auth extends Base {
|
||||
* Get the currently signed in user
|
||||
* @return {Promise}
|
||||
*/
|
||||
get currentUser(): User|null {
|
||||
get currentUser(): User | null {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
import { NativeModules } from 'react-native';
|
||||
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
|
||||
const FirebaseRemoteConfig = NativeModules.RNFirebaseRemoteConfig;
|
||||
|
||||
@ -15,6 +16,10 @@ type RemoteConfigOptions = {}
|
||||
export default class RemoteConfig extends Base {
|
||||
constructor(firebase: Object, options: RemoteConfigOptions = {}) {
|
||||
super(firebase, options);
|
||||
if (FirebaseRemoteConfig.nativeSDKMissing) {
|
||||
return nativeSDKMissing('remote config');
|
||||
}
|
||||
|
||||
this.namespace = 'firebase:config';
|
||||
this.developerModeEnabled = false;
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
// @flow
|
||||
import { NativeModules } from 'react-native';
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
|
||||
const FirebaseCrash = NativeModules.RNFirebaseCrash;
|
||||
|
||||
export default class Crash extends Base {
|
||||
export default class Crash {
|
||||
constructor() {
|
||||
if (FirebaseCrash.nativeSDKMissing) {
|
||||
return nativeSDKMissing('crash');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message that will appear in a subsequent crash report.
|
||||
* @param {string} message
|
||||
|
@ -8,7 +8,7 @@ import { Base } from './../base';
|
||||
import Snapshot from './snapshot';
|
||||
import Reference from './reference';
|
||||
import TransactionHandler from './transaction';
|
||||
import { promisify } from './../../utils';
|
||||
import { promisify, nativeSDKMissing } from './../../utils';
|
||||
|
||||
const FirebaseDatabase = NativeModules.RNFirebaseDatabase;
|
||||
const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase);
|
||||
@ -19,6 +19,10 @@ const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase);
|
||||
export default class Database extends Base {
|
||||
constructor(firebase: Object, options: Object = {}) {
|
||||
super(firebase, options);
|
||||
if (FirebaseDatabase.nativeSDKMissing) {
|
||||
return nativeSDKMissing('database');
|
||||
}
|
||||
|
||||
this.references = {};
|
||||
this.serverTimeOffset = 0;
|
||||
this.persistenceEnabled = false;
|
||||
@ -83,12 +87,10 @@ export default class Database extends Base {
|
||||
* @param origCB
|
||||
* @returns {*}
|
||||
*/
|
||||
off(
|
||||
refId: number,
|
||||
// $FlowFixMe
|
||||
listeners: Array<DatabaseListener>,
|
||||
remainingListenersCount: number
|
||||
) {
|
||||
off(refId: number,
|
||||
// $FlowFixMe
|
||||
listeners: Array<DatabaseListener>,
|
||||
remainingListenersCount: number) {
|
||||
this.log.debug('off() : ', refId, listeners);
|
||||
|
||||
// Delete the reference if there are no more listeners
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
import RemoteMessage from './RemoteMessage';
|
||||
|
||||
const FirebaseMessaging = NativeModules.RNFirebaseMessaging;
|
||||
@ -75,6 +76,10 @@ function finish(data) {
|
||||
export default class Messaging extends Base {
|
||||
constructor(firebase, options = {}) {
|
||||
super(firebase, options);
|
||||
if (FirebaseMessaging.nativeSDKMissing) {
|
||||
return nativeSDKMissing('messaging');
|
||||
}
|
||||
|
||||
this.namespace = 'firebase:messaging';
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
// @flow
|
||||
import { NativeModules } from 'react-native';
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
import Trace from './Trace';
|
||||
|
||||
const FirebasePerformance = NativeModules.RNFirebasePerformance;
|
||||
|
||||
export default class PerformanceMonitoring extends Base {
|
||||
export default class PerformanceMonitoring {
|
||||
constructor() {
|
||||
if (FirebasePerformance.nativeSDKMissing) {
|
||||
return nativeSDKMissing('perf');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Globally enable or disable performance monitoring
|
||||
|
@ -2,6 +2,7 @@
|
||||
import { NativeModules, NativeEventEmitter } from 'react-native';
|
||||
|
||||
import { Base } from './../base';
|
||||
import { nativeSDKMissing } from './../../utils';
|
||||
import StorageRef from './reference';
|
||||
|
||||
const FirebaseStorage = NativeModules.RNFirebaseStorage;
|
||||
@ -19,6 +20,10 @@ export default class Storage extends Base {
|
||||
*/
|
||||
constructor(firebase: Object, options: StorageOptionsType = {}) {
|
||||
super(firebase, options);
|
||||
if (FirebaseStorage.nativeSDKMissing) {
|
||||
return nativeSDKMissing('storage');
|
||||
}
|
||||
|
||||
this.subscriptions = {};
|
||||
|
||||
this.successListener = FirebaseStorageEvt.addListener(
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
@ -27,6 +29,15 @@ const _handler = (resolve, reject, errorPrefix, err, resp) => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export function nativeSDKMissing(sdkName) {
|
||||
if (Platform.OS === 'ios') {
|
||||
console.warn(`Firebase ${sdkName} native sdk has not been included in your podfile - ${sdkName} methods have been disabled.`);
|
||||
} else {
|
||||
console.warn(`Firebase ${sdkName} native sdk has not been included in your build.gradle file - ${sdkName} methods have been disabled.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function toWebSDKErrorCode(code: any, prefix: string): string {
|
||||
if (!code || typeof code !== 'string') return '';
|
||||
return code.toLowerCase().replace('error_', prefix).replace(/_/g, '-');
|
||||
@ -40,11 +51,9 @@ export function toWebSDKErrorCode(code: any, prefix: string): string {
|
||||
* @param joiner
|
||||
* @returns {*}
|
||||
*/
|
||||
export function deepGet(
|
||||
object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'
|
||||
): any {
|
||||
export function deepGet(object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'): any {
|
||||
const keys = path.split(joiner);
|
||||
|
||||
let i = 0;
|
||||
@ -68,11 +77,9 @@ export function deepGet(
|
||||
* @param joiner
|
||||
* @returns {*}
|
||||
*/
|
||||
export function deepExists(
|
||||
object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'
|
||||
): boolean {
|
||||
export function deepExists(object: Object,
|
||||
path: string,
|
||||
joiner?: string = '/'): boolean {
|
||||
const keys = path.split(joiner);
|
||||
|
||||
let i = 0;
|
||||
@ -161,11 +168,9 @@ export function noop(): void {
|
||||
* @param NativeModule
|
||||
* @param errorPrefix
|
||||
*/
|
||||
export function promisify(
|
||||
fn: Function | string,
|
||||
NativeModule: Object,
|
||||
errorPrefix?: string
|
||||
): (args: any) => Promise<> {
|
||||
export function promisify(fn: Function | string,
|
||||
NativeModule: Object,
|
||||
errorPrefix?: string): (args: any) => Promise<> {
|
||||
return (...args) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const _fn = typeof fn === 'function' ? fn : NativeModule[fn];
|
||||
@ -184,12 +189,10 @@ export function promisify(
|
||||
* @param callback
|
||||
* @private
|
||||
*/
|
||||
function _delayChunk(
|
||||
collection: Array<*>,
|
||||
chunkSize: number,
|
||||
operation: Function,
|
||||
callback: Function
|
||||
): void {
|
||||
function _delayChunk(collection: Array<*>,
|
||||
chunkSize: number,
|
||||
operation: Function,
|
||||
callback: Function): void {
|
||||
const length = collection.length;
|
||||
const iterations = Math.ceil(length / chunkSize);
|
||||
|
||||
@ -217,12 +220,10 @@ function _delayChunk(
|
||||
* @param iterator
|
||||
* @param cb
|
||||
*/
|
||||
export function each(
|
||||
array: Array<*>,
|
||||
chunkSize: number | Function,
|
||||
iterator: Function,
|
||||
cb?: Function
|
||||
): void {
|
||||
export function each(array: Array<*>,
|
||||
chunkSize: number | Function,
|
||||
iterator: Function,
|
||||
cb?: Function): void {
|
||||
if (typeof chunkSize === 'function') {
|
||||
cb = iterator;
|
||||
iterator = chunkSize;
|
||||
@ -252,12 +253,10 @@ export function typeOf(value: any): string {
|
||||
* @param cb
|
||||
* @returns {*}
|
||||
*/
|
||||
export function map(
|
||||
array: Array<*>,
|
||||
chunkSize: number | Function,
|
||||
iterator: Function,
|
||||
cb?: Function
|
||||
): void {
|
||||
export function map(array: Array<*>,
|
||||
chunkSize: number | Function,
|
||||
iterator: Function,
|
||||
cb?: Function): void {
|
||||
if (typeof chunkSize === 'function') {
|
||||
cb = iterator;
|
||||
iterator = chunkSize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user