aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js18
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 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed, observable } from 'mobx'; 2import { action, computed, observable, extendObservable } from 'mobx';
3 3
4import Store from './lib/Store'; 4import Store from './lib/Store';
5import Request from './lib/Request'; 5import Request from './lib/Request';
6import CachedRequest from './lib/CachedRequest'; 6import CachedRequest from './lib/CachedRequest';
7import { gaEvent } from '../lib/analytics'; 7import { gaEvent } from '../lib/analytics';
8import { DEFAULT_APP_SETTINGS } from '../config'; 8import SettingsModel from '../models/Settings';
9 9
10export default class SettingsStore extends Store { 10export 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 }