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/store.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/store.js')
-rw-r--r-- | docs/example-feature/store.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/docs/example-feature/store.js b/docs/example-feature/store.js new file mode 100644 index 000000000..d8acfdca3 --- /dev/null +++ b/docs/example-feature/store.js | |||
@@ -0,0 +1,32 @@ | |||
1 | import { action, observable, reaction } from 'mobx'; | ||
2 | import Store from '../../src/stores/lib/Store'; | ||
3 | import Request from '../../src/stores/lib/Request'; | ||
4 | |||
5 | const debug = require('debug')('Franz:feature:EXAMPLE_FEATURE:store'); | ||
6 | |||
7 | export class ExampleFeatureStore extends Store { | ||
8 | @observable getNameRequest = new Request(this.api, 'getName'); | ||
9 | |||
10 | constructor(stores, api, actions, state) { | ||
11 | super(stores, api, actions); | ||
12 | this.state = state; | ||
13 | } | ||
14 | |||
15 | setup() { | ||
16 | debug('fetching name from api'); | ||
17 | this.getNameRequest.execute(); | ||
18 | |||
19 | // Update the name on the state when the request resolved | ||
20 | reaction( | ||
21 | () => this.getNameRequest.result, | ||
22 | name => this._setName(name), | ||
23 | ); | ||
24 | } | ||
25 | |||
26 | @action _setName = (name) => { | ||
27 | debug('setting name', name); | ||
28 | this.state.name = name; | ||
29 | }; | ||
30 | } | ||
31 | |||
32 | export default ExampleFeatureStore; | ||