You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.any.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @flow
  2. import { toState } from '../base/redux';
  3. import { getServerURL } from '../base/settings';
  4. /**
  5. * Gets the value of a specific React {@code Component} prop of the currently
  6. * mounted {@link App}.
  7. *
  8. * @param {Function|Object} stateful - The redux store or {@code getState}
  9. * function.
  10. * @param {string} propName - The name of the React {@code Component} prop of
  11. * the currently mounted {@code App} to get.
  12. * @returns {*} The value of the specified React {@code Compoennt} prop of the
  13. * currently mounted {@code App}.
  14. */
  15. export function getAppProp(stateful: Function | Object, propName: string) {
  16. const state = toState(stateful)['features/app'];
  17. if (state) {
  18. const { app } = state;
  19. if (app) {
  20. return app.props[propName];
  21. }
  22. }
  23. return undefined;
  24. }
  25. /**
  26. * Retrieves the default URL for the app. This can either come from a prop to
  27. * the root App component or be configured in the settings.
  28. *
  29. * @param {Function|Object} stateful - The redux store or {@code getState}
  30. * function.
  31. * @returns {string} - Default URL for the app.
  32. */
  33. export function getDefaultURL(stateful: Function | Object) {
  34. const state = toState(stateful);
  35. const { app } = state['features/app'];
  36. // If the execution environment provides a Location abstraction (e.g. a Web
  37. // browser), then we'll presume it's the one and only base URL it can be on.
  38. const windowLocation = app.getWindowLocation();
  39. if (windowLocation) {
  40. const href = windowLocation.toString();
  41. if (href) {
  42. return href;
  43. }
  44. }
  45. return getAppProp(state, 'defaultURL') || getServerURL(state);
  46. }