[internals][js] remove legacy options
arg for module constructors and cleanup constructor args
This commit is contained in:
parent
a2205160d8
commit
a2c56a5be4
@ -32,17 +32,21 @@ export default class Database extends ModuleBase {
|
|||||||
|
|
||||||
_serviceUrl: string;
|
_serviceUrl: string;
|
||||||
|
|
||||||
constructor(appOrUrl: App | string, options: Object = {}) {
|
constructor(appOrCustomUrl: App | string, customUrl?: string) {
|
||||||
let app;
|
let app;
|
||||||
let serviceUrl;
|
let url;
|
||||||
if (typeof appOrUrl === 'string') {
|
|
||||||
|
if (typeof appOrCustomUrl === 'string') {
|
||||||
app = firebase.app();
|
app = firebase.app();
|
||||||
serviceUrl = appOrUrl.endsWith('/') ? appOrUrl : `${appOrUrl}/`;
|
url = appOrCustomUrl;
|
||||||
} else {
|
} else {
|
||||||
app = appOrUrl;
|
app = appOrCustomUrl;
|
||||||
serviceUrl = app.options.databaseURL;
|
url = customUrl || app.options.databaseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enforce trailing slash
|
||||||
|
url = url.endsWith('/') ? url : `${url}/`;
|
||||||
|
|
||||||
super(
|
super(
|
||||||
app,
|
app,
|
||||||
{
|
{
|
||||||
@ -52,15 +56,15 @@ export default class Database extends ModuleBase {
|
|||||||
hasCustomUrlSupport: true,
|
hasCustomUrlSupport: true,
|
||||||
namespace: NAMESPACE,
|
namespace: NAMESPACE,
|
||||||
},
|
},
|
||||||
serviceUrl
|
url
|
||||||
);
|
);
|
||||||
|
|
||||||
this._serverTimeOffset = 0;
|
this._serverTimeOffset = 0;
|
||||||
this._serviceUrl = serviceUrl;
|
this._serviceUrl = serviceUrl;
|
||||||
this._transactionHandler = new TransactionHandler(this);
|
this._transactionHandler = new TransactionHandler(this);
|
||||||
|
|
||||||
if (options.persistence) {
|
if (app.options.persistence) {
|
||||||
getNativeModule(this).setPersistence(options.persistence);
|
getNativeModule(this).setPersistence(app.options.persistence);
|
||||||
}
|
}
|
||||||
|
|
||||||
// server time listener
|
// server time listener
|
||||||
|
@ -40,16 +40,19 @@ function errorOrResult(possibleError): HttpsCallablePromise {
|
|||||||
return Promise.resolve(possibleError);
|
return Promise.resolve(possibleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -------------
|
||||||
|
* functions()
|
||||||
|
* -------------
|
||||||
|
*/
|
||||||
export default class Functions extends ModuleBase {
|
export default class Functions extends ModuleBase {
|
||||||
_region: string;
|
constructor(appOrRegion: App, region?: string = 'us-central1') {
|
||||||
|
|
||||||
constructor(appOrRegion: App, region: string = 'us-central1') {
|
|
||||||
let _app = appOrRegion;
|
let _app = appOrRegion;
|
||||||
let _region = region;
|
let _region = region;
|
||||||
|
|
||||||
if (typeof appOrRegion === 'string') {
|
if (typeof _app === 'string') {
|
||||||
|
_region = _app;
|
||||||
_app = firebase.app();
|
_app = firebase.app();
|
||||||
_region = appOrRegion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super(
|
super(
|
||||||
@ -77,7 +80,7 @@ export default class Functions extends ModuleBase {
|
|||||||
*/
|
*/
|
||||||
httpsCallable(name: string): HttpsCallable {
|
httpsCallable(name: string): HttpsCallable {
|
||||||
return (data?: any): HttpsCallablePromise => {
|
return (data?: any): HttpsCallablePromise => {
|
||||||
const promise = getNativeModule(this).httpsCallable(this._region, name, {
|
const promise = getNativeModule(this).httpsCallable(name, {
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ export default {
|
|||||||
|
|
||||||
if (!APP_MODULES[appInstanceIdentifier][namespace]) {
|
if (!APP_MODULES[appInstanceIdentifier][namespace]) {
|
||||||
APP_MODULES[appInstanceIdentifier][namespace] = new InstanceClass(
|
APP_MODULES[appInstanceIdentifier][namespace] = new InstanceClass(
|
||||||
customUrlOrRegion || app,
|
app,
|
||||||
app.options
|
customUrlOrRegion
|
||||||
);
|
);
|
||||||
|
|
||||||
// only check once on new app namespace instance
|
// only check once on new app namespace instance
|
||||||
@ -185,9 +185,12 @@ export default {
|
|||||||
statics: S,
|
statics: S,
|
||||||
moduleName: FirebaseModuleName
|
moduleName: FirebaseModuleName
|
||||||
): FirebaseModuleAndStatics<M, S> {
|
): FirebaseModuleAndStatics<M, S> {
|
||||||
const getModule = (appOrUrlOrRegion?: App | string): FirebaseModule => {
|
const getModule = (
|
||||||
|
appOrUrlOrRegion?: App | string,
|
||||||
|
customUrlOrRegion?: string
|
||||||
|
): FirebaseModule => {
|
||||||
let _app = appOrUrlOrRegion;
|
let _app = appOrUrlOrRegion;
|
||||||
let _customUrlOrRegion: ?string = null;
|
let _customUrlOrRegion: ?string = customUrlOrRegion || null;
|
||||||
|
|
||||||
if (typeof appOrUrlOrRegion === 'string' && namespace === 'database') {
|
if (typeof appOrUrlOrRegion === 'string' && namespace === 'database') {
|
||||||
_app = null;
|
_app = null;
|
||||||
|
@ -42,7 +42,13 @@ export const initialiseNativeModule = (
|
|||||||
config: FirebaseModuleConfig,
|
config: FirebaseModuleConfig,
|
||||||
customUrlOrRegion: ?string
|
customUrlOrRegion: ?string
|
||||||
): Object => {
|
): Object => {
|
||||||
const { moduleName, hasMultiAppSupport, hasCustomUrlSupport, hasRegionsSupport, namespace } = config;
|
const {
|
||||||
|
moduleName,
|
||||||
|
hasMultiAppSupport,
|
||||||
|
hasCustomUrlSupport,
|
||||||
|
hasRegionsSupport,
|
||||||
|
namespace,
|
||||||
|
} = config;
|
||||||
const nativeModule = NativeModules[moduleName];
|
const nativeModule = NativeModules[moduleName];
|
||||||
const key = nativeModuleKey(module);
|
const key = nativeModuleKey(module);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user