import { autorun, reaction } from 'mobx';

import { DEFAULT_FEATURES_CONFIG } from '../../config';

const debug = require('debug')('Franz:feature:spellchecker');

export const config = {
  isPremiumFeature: DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature,
};

export default function init(stores) {
  reaction(
    () => stores.features.features.isSpellcheckerPremiumFeature,
    (enabled, r) => {
      debug('Initializing `spellchecker` feature');

      // Dispose the reaction to run this only once
      r.dispose();

      const { isSpellcheckerPremiumFeature } = stores.features.features;

      config.isPremiumFeature = isSpellcheckerPremiumFeature !== undefined ? isSpellcheckerPremiumFeature : DEFAULT_FEATURES_CONFIG.isSpellcheckerPremiumFeature;

      autorun(() => {
        if (!stores.user.data.isPremium && config.isPremiumFeature) {
          debug('Override settings.spellcheckerEnabled flag to false');

          Object.assign(stores.settings.all.app, {
            enableSpellchecking: false,
          });
        }
      });
    },
  );
}


@@ -11,24 +11,26 @@
 utorun, 
-reaction
+observable
  %7D from 
@@ -180,16 +180,27 @@
 onfig = 
+observable(
 %7B%0A  isPr
@@ -268,16 +268,17 @@
 ature,%0A%7D
+)
 ;%0A%0Aexpor
@@ -317,232 +317,73 @@
 %7B%0A  
-reaction(%0A    () =%3E stores.features.features.isSpellcheckerPremiumFeature,%0A    (enabled, r) =%3E %7B%0A      debug('Initializing %60spellchecker%60 feature');%0A%0A      // Dispose the reaction to run this only once%0A      r.dispose();%0A%0A  
+debug('Initializing %60spellchecker%60 feature');%0A%0A  autorun(() =%3E %7B%0A
     
@@ -450,18 +450,16 @@
 tures;%0A%0A
-  
     conf
@@ -615,34 +615,8 @@
 e;%0A%0A
-      autorun(() =%3E %7B%0A    
     
@@ -677,16 +677,55 @@
 ture
+ && stores.settings.app.enableSpellchecking
 ) %7B%0A
-    
     
@@ -795,20 +795,16 @@
 %0A%0A      
-  
-  
 Object.a
@@ -829,12 +829,8 @@
 ngs.
-all.
 app,
@@ -840,20 +840,16 @@
         
-   
- 
 enableSp
@@ -878,47 +878,22 @@
     
-    %7D);%0A        %7D%0A      %7D);%0A    %7D,%0A  );%0A%7D%0A
+%7D);%0A    %7D%0A  %7D);%0A%7D
 %0A

Simplify spellchecker feature init