import {debounce} from '../common/utils';
import {SET_OPTIONS} from '../actions/settings';
import {SET_DOCK_OPTIONS} from '../actions/dock';

import storage from '../common/storage';

const sync = debounce(state => storage.sync(state), 1000);

const chromeStorage = store => next => action => {
  const result = next(action);
  if (action.type !== SET_OPTIONS && action.type !== SET_DOCK_OPTIONS) return result;
  sync(store.getState());
  return result;
};

export default chromeStorage;

import {debounce} from '../common/utils';

import {SET_OPTIONS} from '../actions/settings';
import {SET_DOCK_OPTIONS} from '../actions/dock';
import {SET_INTRO} from '../actions/intro';

import storage from '../common/storage';

const sync = debounce(state => storage.sync(state), 1000);

const actions = [
  SET_INTRO, // after welcome screen
  SET_DOCK_OPTIONS, // when any dock options were changed
  SET_OPTIONS // when any other options were changed
];

const chromeStorage = store => next => action => {
  const result = next(action);
  if (!actions.includes(action.type)) return result;
  sync(store.getState());
  return result;
};

export default chromeStorage;

save settings when intro ends