diff options
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r-- | src/features/workspaces/store.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js new file mode 100644 index 000000000..4b4e729ed --- /dev/null +++ b/src/features/workspaces/store.js | |||
@@ -0,0 +1,29 @@ | |||
1 | import { observable, reaction } from 'mobx'; | ||
2 | import Store from '../../stores/lib/Store'; | ||
3 | import CachedRequest from '../../stores/lib/CachedRequest'; | ||
4 | |||
5 | const debug = require('debug')('Franz:feature:workspaces'); | ||
6 | |||
7 | export default class WorkspacesStore extends Store { | ||
8 | @observable allWorkspacesRequest = new CachedRequest(this.api, 'getUserWorkspaces'); | ||
9 | |||
10 | constructor(stores, api, actions, state) { | ||
11 | super(stores, api, actions); | ||
12 | this.state = state; | ||
13 | } | ||
14 | |||
15 | setup() { | ||
16 | debug('fetching user workspaces'); | ||
17 | this.allWorkspacesRequest.execute(); | ||
18 | |||
19 | reaction( | ||
20 | () => this.allWorkspacesRequest.result, | ||
21 | workspaces => this.setWorkspaces(workspaces), | ||
22 | ); | ||
23 | } | ||
24 | |||
25 | setWorkspaces = (workspaces) => { | ||
26 | debug('setting user workspaces', workspaces.slice()); | ||
27 | this.state.workspaces = workspaces; | ||
28 | }; | ||
29 | } | ||