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.js 1023B

1234567891011121314151617181920212223242526272829303132
  1. // @flow
  2. import { getAppProp } from '../app';
  3. import { toState } from '../redux';
  4. /**
  5. * Gets the value of a specific feature flag.
  6. *
  7. * @param {Function|Object} stateful - The redux store or {@code getState}
  8. * function.
  9. * @param {string} flag - The name of the React {@code Component} prop of
  10. * the currently mounted {@code App} to get.
  11. * @param {*} defaultValue - A default value for the flag, in case it's not defined.
  12. * @returns {*} The value of the specified React {@code Compoennt} prop of the
  13. * currently mounted {@code App}.
  14. */
  15. export function getFeatureFlag(stateful: Function | Object, flag: string, defaultValue: any) {
  16. const state = toState(stateful)['features/base/flags'];
  17. if (state) {
  18. const value = state[flag];
  19. if (typeof value !== 'undefined') {
  20. return value;
  21. }
  22. }
  23. // Maybe the value hasn't made it to the redux store yet, check the app props.
  24. const flags = getAppProp(stateful, 'flags') || {};
  25. return flags[flag] || defaultValue;
  26. }