From 5573ab7e17400229dd5d79fa50808b38293872fc Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 23 Nov 2017 11:30:19 +0100 Subject: Add SettingsModel and fix issue with improper mobx data handling --- src/stores/SettingsStore.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index ad3c53ccf..30058f41d 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -1,11 +1,10 @@ import { ipcRenderer } from 'electron'; -import { action, computed, observable } from 'mobx'; +import { action, computed, observable, extendObservable } from 'mobx'; import Store from './lib/Store'; import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; import { gaEvent } from '../lib/analytics'; -import { DEFAULT_APP_SETTINGS } from '../config'; export default class SettingsStore extends Store { @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); @@ -18,10 +17,6 @@ export default class SettingsStore extends Store { // Register action handlers this.actions.settings.update.listen(this._update.bind(this)); this.actions.settings.remove.listen(this._remove.bind(this)); - - // this.registerReactions([ - // this._shareSettingsWithMainProcess.bind(this), - // ]); } setup() { @@ -30,14 +25,14 @@ export default class SettingsStore extends Store { } @computed get all() { - return observable(Object.assign(DEFAULT_APP_SETTINGS, this.allSettingsRequest.result)); + return this.allSettingsRequest.result || {}; } @action async _update({ settings }) { await this.updateSettingsRequest.execute(settings)._promise; - this.allSettingsRequest.patch((result) => { + await this.allSettingsRequest.patch((result) => { if (!result) return; - Object.assign(result, settings); + extendObservable(result, settings); }); // We need a little hack to wait until everything is patched -- cgit v1.2.3-70-g09d2