[core] add extendApp support
This commit is contained in:
parent
929352f8d3
commit
67dc829427
|
@ -1,6 +1,7 @@
|
|||
import { NativeModules } from 'react-native';
|
||||
|
||||
import INTERNALS from './internals';
|
||||
import { isObject } from './utils';
|
||||
|
||||
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||
|
@ -34,6 +35,7 @@ export default class FirebaseApp {
|
|||
this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging);
|
||||
this.perf = this._staticsOrModuleInstance({}, Performance);
|
||||
this.storage = this._staticsOrModuleInstance(StorageStatics, Storage);
|
||||
this._extendedProps = {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,6 +80,26 @@ export default class FirebaseApp {
|
|||
return Object.assign({}, this._options);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param props
|
||||
*/
|
||||
extendApp(props: Object) {
|
||||
if (!isObject(props)) throw new Error(INTERNALS.ERROR_MISSING_ARG('Object', 'extendApp'));
|
||||
const keys = Object.keys(props);
|
||||
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
|
||||
if (!this._extendedProps[key] && Object.hasOwnProperty.call(this, key)) {
|
||||
throw new Error(INTERNALS.ERROR_PROTECTED_PROP(key));
|
||||
}
|
||||
|
||||
this[key] = props[key];
|
||||
this._extendedProps[key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {Promise}
|
||||
|
|
|
@ -63,6 +63,20 @@ export default {
|
|||
return `Missing required callback for method ${method}().`;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
ERROR_MISSING_ARG(type, method) {
|
||||
return `Missing required argument of type '${type}' for method '${method}()'.`;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
ERROR_PROTECTED_PROP(name) {
|
||||
return `Property '${name}' is protected and can not be overridden by extendApp.`;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
* @param namespace
|
||||
|
|
Loading…
Reference in New Issue