blob: b7e1090e85882a60693e0dd59f6ca4cd9de969a3 (
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 { observable, reaction } from 'mobx';
import { merge } from 'lodash';
import WorkspacesStore from './store';
import api from './api';
const debug = require('debug')('Franz:feature:workspaces');
let store = null;
const defaultState = { workspaces: [] };
export const state = observable(defaultState);
export default function initWorkspaces(stores, actions) {
const { features, user } = stores;
reaction(
() => features.features.isWorkspaceEnabled && user.isLoggedIn,
(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;
// Reset state to default
merge(state, defaultState);
}
},
{
fireImmediately: true,
},
);
}
|