aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/serviceLimit/index.js
blob: 76f996195382c385c6a1bd07d1619111143e4abf (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
32
33
import { reaction } from 'mobx';
import { ServiceLimitStore } from './store';

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

export const DEFAULT_SERVICE_LIMIT = 3;

let store = null;

export const serviceLimitStore = new ServiceLimitStore();

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

  // Toggle serviceLimit feature
  reaction(
    () => (
      features.features.hasServiceLimit
    ),
    (isEnabled) => {
      if (isEnabled) {
        debug('Initializing `serviceLimit` feature');
        store = serviceLimitStore.start(stores, actions);
      } else if (store) {
        debug('Disabling `serviceLimit` feature');
        serviceLimitStore.stop();
      }
    },
    {
      fireImmediately: true,
    },
  );
}