blob: af859af2620c6bd2182af53990a38d84371564f6 (
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
35
36
|
import { reaction, runInAction } from 'mobx';
import { ExampleFeatureStore } from './store';
import state, { resetState } from './state';
import api from './api';
const debug = require('debug')('Franz:feature:EXAMPLE_FEATURE');
let store = null;
export default function initAnnouncements(stores, actions) {
const { features } = stores;
// Toggle workspace feature
reaction(
() => (
features.features.isExampleFeatureEnabled
),
(isEnabled) => {
if (isEnabled) {
debug('Initializing `EXAMPLE_FEATURE` feature');
store = new ExampleFeatureStore(stores, api, actions, state);
store.initialize();
runInAction(() => { state.isFeatureActive = true; });
} else if (store) {
debug('Disabling `EXAMPLE_FEATURE` feature');
runInAction(() => { state.isFeatureActive = false; });
store.teardown();
store = null;
resetState(); // Reset state to default
}
},
{
fireImmediately: true,
},
);
}
|