rn: simplified code

There is no need for AbstractApp to require some getWindowLocation function.
It's only used in one place and we even polyfill it on mobile.

Thus replace it's usage with more specific functions.
This commit is contained in:
Saúl Ibarra Corretgé 2019-02-07 15:37:35 +01:00 committed by Saúl Ibarra Corretgé
parent 56135bd085
commit e4c3e15791
5 changed files with 38 additions and 60 deletions

View File

@ -79,22 +79,6 @@ export class AbstractApp extends BaseApp<Props, *> {
});
}
/**
* Gets a {@code Location} object from the window with information about the
* current location of the document. Explicitly defined to allow extenders
* to override because React Native does not usually have a location
* property on its window unless debugging remotely in which case the
* browser that is the remote debugger will provide a location property on
* the window.
*
* @public
* @returns {Location} A {@code Location} object with information about the
* current location of the document.
*/
getWindowLocation() {
return undefined;
}
/**
* Creates an extra {@link ReactElement}s to be added (unconditionaly)
* alongside the main element.

View File

@ -17,16 +17,6 @@ import { AbstractApp } from './AbstractApp';
* @extends AbstractApp
*/
export class App extends AbstractApp {
/**
* Gets a Location object from the window with information about the current
* location of the document.
*
* @inheritdoc
*/
getWindowLocation() {
return window.location;
}
/**
* Overrides the parent method to inject {@link AtlasKitThemeProvider} as
* the top most component.

View File

@ -1,32 +0,0 @@
// @flow
import { getAppProp } from '../base/app';
import { toState } from '../base/redux';
import { getServerURL } from '../base/settings';
/**
* Retrieves the default URL for the app. This can either come from a prop to
* the root App component or be configured in the settings.
*
* @param {Function|Object} stateful - The redux store or {@code getState}
* function.
* @returns {string} - Default URL for the app.
*/
export function getDefaultURL(stateful: Function | Object) {
const state = toState(stateful);
const { app } = state['features/base/app'];
// If the execution environment provides a Location abstraction (e.g. a Web
// browser), then we'll presume it's the one and only base URL it can be on.
const windowLocation = app.getWindowLocation();
if (windowLocation) {
const href = windowLocation.toString();
if (href) {
return href;
}
}
return getAppProp(state, 'defaultURL') || getServerURL(state);
}

View File

@ -2,7 +2,23 @@
import { NativeModules } from 'react-native';
export * from './functions.any';
import { getAppProp } from '../base/app';
import { toState } from '../base/redux';
import { getServerURL } from '../base/settings';
/**
* Retrieves the default URL for the app. This can either come from a prop to
* the root App component or be configured in the settings.
*
* @param {Function|Object} stateful - The redux store or {@code getState}
* function.
* @returns {string} - Default URL for the app.
*/
export function getDefaultURL(stateful: Function | Object) {
const state = toState(stateful);
return getAppProp(state, 'defaultURL') || getServerURL(state);
}
/**
* Returns application name.

View File

@ -1,9 +1,29 @@
// @flow
export * from './functions.any';
import { toState } from '../base/redux';
import { getServerURL } from '../base/settings';
declare var interfaceConfig: Object;
/**
* Retrieves the default URL for the app. This can either come from a prop to
* the root App component or be configured in the settings.
*
* @param {Function|Object} stateful - The redux store or {@code getState}
* function.
* @returns {string} - Default URL for the app.
*/
export function getDefaultURL(stateful: Function | Object) {
const state = toState(stateful);
const { href } = window.location;
if (href) {
return href;
}
return getServerURL(state);
}
/**
* Returns application name.
*