aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/index.js
blob: 50ac3b4146416b828060c93b0e9f8387d7169c63 (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
34
import { reaction } from 'mobx';
import WorkspacesStore from './store';
import api from './api';
import { state, resetState } from './state';

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

let store = null;

export default function initWorkspaces(stores, actions) {
  const { features, user } = stores;
  reaction(
    () => (
      features.features.isWorkspaceEnabled && (
        !features.features.isWorkspacePremiumFeature || user.data.isPremium
      )
    ),
    (isEnabled) => {
      if (isEnabled) {
        debug('Initializing `workspaces` feature');
        store = new WorkspacesStore(stores, api, actions, state);
        store.initialize();
      } else if (store) {
        debug('Disabling `workspaces` feature');
        store.teardown();
        store = null;
        resetState(); // Reset state to default
      }
    },
    {
      fireImmediately: true,
    },
  );
}