diff options
author | 2019-03-12 18:20:56 +0100 | |
---|---|---|
committer | 2019-03-12 18:20:56 +0100 | |
commit | d51283b5f89d42814a340b7cd77e6544d23aa243 (patch) | |
tree | f0e56e577d53987d22db44a8a87e5f37b8ea6ea8 /docs/example-feature/index.js | |
parent | add useful helpers for building standalone app features (diff) | |
download | ferdium-app-d51283b5f89d42814a340b7cd77e6544d23aa243.tar.gz ferdium-app-d51283b5f89d42814a340b7cd77e6544d23aa243.tar.zst ferdium-app-d51283b5f89d42814a340b7cd77e6544d23aa243.zip |
add example feature template to docs folder
Diffstat (limited to 'docs/example-feature/index.js')
-rw-r--r-- | docs/example-feature/index.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/example-feature/index.js b/docs/example-feature/index.js new file mode 100644 index 000000000..af859af26 --- /dev/null +++ b/docs/example-feature/index.js | |||
@@ -0,0 +1,36 @@ | |||
1 | import { reaction, runInAction } from 'mobx'; | ||
2 | import { ExampleFeatureStore } from './store'; | ||
3 | import state, { resetState } from './state'; | ||
4 | import api from './api'; | ||
5 | |||
6 | const debug = require('debug')('Franz:feature:EXAMPLE_FEATURE'); | ||
7 | |||
8 | let store = null; | ||
9 | |||
10 | export default function initAnnouncements(stores, actions) { | ||
11 | const { features } = stores; | ||
12 | |||
13 | // Toggle workspace feature | ||
14 | reaction( | ||
15 | () => ( | ||
16 | features.features.isExampleFeatureEnabled | ||
17 | ), | ||
18 | (isEnabled) => { | ||
19 | if (isEnabled) { | ||
20 | debug('Initializing `EXAMPLE_FEATURE` feature'); | ||
21 | store = new ExampleFeatureStore(stores, api, actions, state); | ||
22 | store.initialize(); | ||
23 | runInAction(() => { state.isFeatureActive = true; }); | ||
24 | } else if (store) { | ||
25 | debug('Disabling `EXAMPLE_FEATURE` feature'); | ||
26 | runInAction(() => { state.isFeatureActive = false; }); | ||
27 | store.teardown(); | ||
28 | store = null; | ||
29 | resetState(); // Reset state to default | ||
30 | } | ||
31 | }, | ||
32 | { | ||
33 | fireImmediately: true, | ||
34 | }, | ||
35 | ); | ||
36 | } | ||