Skip to content

Instantly share code, notes, and snippets.

@mmollaverdi
Last active August 17, 2016 21:24
Show Gist options
  • Select an option

  • Save mmollaverdi/384c3d856b74f9ad961fe6ddd1193657 to your computer and use it in GitHub Desktop.

Select an option

Save mmollaverdi/384c3d856b74f9ad961fe6ddd1193657 to your computer and use it in GitHub Desktop.
Before After
export default function featureToggles(state={}, action) {
  switch (action.type) {
    case Actions.FEATURE_TOGGLES_UPDATED:
      return { ...state, ...action.data };
    default:
      return state;
  }
}

|

class FeatureToggleStore extends MapStore {
  getInitialState() {
    return { featureToggles: {} };
  }
  
  reduce(state, payload) {
    const { action } = payload;
    switch (action.type) {
      case Actions.FEATURE_TOGGLES_UPDATED:
        const featureToggles = {
          ...state.featureToggles,
          ...action.data
        };
        return { featureToggles };
      default:
        return state;
    }
  }

  getFeatureToggles() {
    return this.getState().featureToggles;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment