From d70ad5f7f278babab9f017e17eac9e5e9fe8ec5d Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Sun, 2 Dec 2018 00:21:13 +0100 Subject: Simplify spellchecker feature init --- src/features/spellchecker/index.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'src/features/spellchecker') diff --git a/src/features/spellchecker/index.js b/src/features/spellchecker/index.js index 454096e4e..63506103c 100644 --- a/src/features/spellchecker/index.js +++ b/src/features/spellchecker/index.js @@ -1,36 +1,27 @@ -import { autorun, reaction } from 'mobx'; +import { autorun, observable } from 'mobx'; import { DEFAULT_FEATURES_CONFIG } from '../../config'; const debug = require('debug')('Franz:feature:spellchecker'); -export const config = { +export const config = observable({ isPremiumFeature: DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature, -}; +}); export default function init(stores) { - reaction( - () => stores.features.features.isSpellcheckerPremiumFeature, - (enabled, r) => { - debug('Initializing `spellchecker` feature'); + debug('Initializing `spellchecker` feature'); - // Dispose the reaction to run this only once - r.dispose(); + autorun(() => { + const { isSpellcheckerPremiumFeature } = stores.features.features; - const { isSpellcheckerPremiumFeature } = stores.features.features; + config.isPremiumFeature = isSpellcheckerPremiumFeature !== undefined ? isSpellcheckerPremiumFeature : DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature; - config.isPremiumFeature = isSpellcheckerPremiumFeature !== undefined ? isSpellcheckerPremiumFeature : DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature; + if (!stores.user.data.isPremium && config.isPremiumFeature && stores.settings.app.enableSpellchecking) { + debug('Override settings.spellcheckerEnabled flag to false'); - autorun(() => { - if (!stores.user.data.isPremium && config.isPremiumFeature) { - debug('Override settings.spellcheckerEnabled flag to false'); - - Object.assign(stores.settings.all.app, { - enableSpellchecking: false, - }); - } + Object.assign(stores.settings.app, { + enableSpellchecking: false, }); - }, - ); + } + }); } - -- cgit v1.2.3-54-g00ecf