aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/announcements/index.js
blob: 28f0b10ed1c4dcbc65f1bcece3915870aad3f567 (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
31
import { reaction } from 'mobx';
import { AnnouncementsStore } from './store';

const debug = require('debug')('Ferdi:feature:announcements');

export const GA_CATEGORY_ANNOUNCEMENTS = 'Announcements';

export const announcementsStore = new AnnouncementsStore();

export default function initAnnouncements(stores, actions) {
  const { features } = stores;

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