Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

functions.ts 1.1KB

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