diff --git a/client/js/models/settings.js b/client/js/models/settings.js index 6c4aa616..b4b04bbb 100644 --- a/client/js/models/settings.js +++ b/client/js/models/settings.js @@ -20,19 +20,12 @@ const defaultSettings = { }; class Settings extends events.EventTarget { - save(newSettings, silent) { - newSettings = Object.assign(this.get(), newSettings); - localStorage.setItem('settings', JSON.stringify(newSettings)); - if (silent !== true) { - this.dispatchEvent(new CustomEvent('change', { - detail: { - settings: this.get(), - }, - })); - } + constructor() { + super(); + this.cache = this._getFromLocalStorage(); } - get() { + _getFromLocalStorage() { let ret = Object.assign({}, defaultSettings); try { Object.assign(ret, JSON.parse(localStorage.getItem('settings'))); @@ -40,6 +33,23 @@ class Settings extends events.EventTarget { } return ret; } + + save(newSettings, silent) { + newSettings = Object.assign(this.cache, newSettings); + localStorage.setItem('settings', JSON.stringify(newSettings)); + this.cache = this._getFromLocalStorage(); + if (silent !== true) { + this.dispatchEvent(new CustomEvent('change', { + detail: { + settings: this.cache, + }, + })); + } + } + + get() { + return this.cache; + } }; module.exports = new Settings(); diff --git a/client/js/util/misc.js b/client/js/util/misc.js index 2539384b..aa62097d 100644 --- a/client/js/util/misc.js +++ b/client/js/util/misc.js @@ -4,8 +4,6 @@ const markdown = require('./markdown.js'); const uri = require('./uri.js'); const settings = require('../models/settings.js'); -const tagUnderscoresAsSpaces = settings.get().tagUnderscoresAsSpaces; - function decamelize(str, sep) { sep = sep === undefined ? '-' : sep; return str @@ -201,7 +199,7 @@ function dataURItoBlob(dataURI) { } function getPrettyTagName(tag) { - if (tagUnderscoresAsSpaces) { + if (settings.get().tagUnderscoresAsSpaces) { return tag.replace(/_/g, " "); } return tag;