dispatch/client/js/modules/storage.js

19 lines
484 B
JavaScript
Raw Normal View History

import Cookie from 'js-cookie';
import debounce from 'lodash/debounce';
import { getSelectedTab } from 'state/tab';
2018-04-25 03:36:27 +00:00
import { isChannel, stringifyTab } from 'utils';
import { observe } from 'utils/observe';
2018-03-25 00:34:41 +00:00
const saveTab = debounce(
2018-04-25 03:36:27 +00:00
tab => Cookie.set('tab', stringifyTab(tab), { expires: 30 }),
2018-03-25 00:34:41 +00:00
1000
);
export default function storage({ store }) {
observe(store, getSelectedTab, tab => {
2018-04-25 03:36:27 +00:00
if (isChannel(tab) || (tab.server && !tab.name)) {
saveTab(tab);
}
});
}