aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/planSelection/index.js
blob: 81189207a521e1e055e31faead59634e6e6006c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { reaction } from 'mobx';
import PlanSelectionStore from './store';

const debug = require('debug')('Franz:feature:planSelection');

export const GA_CATEGORY_PLAN_SELECTION = 'planSelection';

export const planSelectionStore = new PlanSelectionStore();

export default function initPlanSelection(stores, actions) {
  stores.planSelection = planSelectionStore;
  const { features } = stores;

  // Toggle planSelection feature
  reaction(
    () => features.features.isPlanSelectionEnabled,
    (isEnabled) => {
      if (isEnabled) {
        debug('Initializing `planSelection` feature');
        planSelectionStore.start(stores, actions);
      } else if (planSelectionStore.isFeatureActive) {
        debug('Disabling `planSelection` feature');
        planSelectionStore.stop();
      }
    },
    {
      fireImmediately: true,
    },
  );
}