diff options
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 331df5c15..da99a720f 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,11 +1,11 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { action, computed, observable } from 'mobx'; | 2 | import { action, computed, observable, extendObservable } from 'mobx'; |
3 | 3 | ||
4 | import Store from './lib/Store'; | 4 | import Store from './lib/Store'; |
5 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | import CachedRequest from './lib/CachedRequest'; | 6 | import CachedRequest from './lib/CachedRequest'; |
7 | import { gaEvent } from '../lib/analytics'; | 7 | import { gaEvent } from '../lib/analytics'; |
8 | import { DEFAULT_APP_SETTINGS } from '../config'; | 8 | import SettingsModel from '../models/Settings'; |
9 | 9 | ||
10 | export default class SettingsStore extends Store { | 10 | export default class SettingsStore extends Store { |
11 | @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); | 11 | @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); |
@@ -18,10 +18,6 @@ export default class SettingsStore extends Store { | |||
18 | // Register action handlers | 18 | // Register action handlers |
19 | this.actions.settings.update.listen(this._update.bind(this)); | 19 | this.actions.settings.update.listen(this._update.bind(this)); |
20 | this.actions.settings.remove.listen(this._remove.bind(this)); | 20 | this.actions.settings.remove.listen(this._remove.bind(this)); |
21 | |||
22 | // this.registerReactions([ | ||
23 | // this._shareSettingsWithMainProcess.bind(this), | ||
24 | // ]); | ||
25 | } | 21 | } |
26 | 22 | ||
27 | setup() { | 23 | setup() { |
@@ -30,14 +26,18 @@ export default class SettingsStore extends Store { | |||
30 | } | 26 | } |
31 | 27 | ||
32 | @computed get all() { | 28 | @computed get all() { |
33 | return observable(Object.assign(DEFAULT_APP_SETTINGS, this.allSettingsRequest.result)); | 29 | return new SettingsModel(this.allSettingsRequest.result); |
34 | } | 30 | } |
35 | 31 | ||
36 | @action async _update({ settings }) { | 32 | @action async _update({ settings }) { |
37 | await this.updateSettingsRequest.execute(settings)._promise; | 33 | await this.updateSettingsRequest.execute(settings)._promise; |
38 | await this.allSettingsRequest.invalidate({ immediately: true }); | 34 | await this.allSettingsRequest.patch((result) => { |
35 | if (!result) return; | ||
36 | extendObservable(result, settings); | ||
37 | }); | ||
39 | 38 | ||
40 | this._shareSettingsWithMainProcess(); | 39 | // We need a little hack to wait until everything is patched |
40 | setTimeout(() => this._shareSettingsWithMainProcess(), 0); | ||
41 | 41 | ||
42 | gaEvent('Settings', 'update'); | 42 | gaEvent('Settings', 'update'); |
43 | } | 43 | } |