2017-05-21 07:53:47 +00:00
|
|
|
import Cookie from 'js-cookie';
|
2017-05-19 06:36:13 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
2017-06-21 06:40:28 +00:00
|
|
|
import { getSelectedTab } from 'state/tab';
|
2020-05-06 02:19:55 +00:00
|
|
|
import { stringifyTab } from 'utils';
|
2018-04-05 19:13:32 +00:00
|
|
|
import { observe } from 'utils/observe';
|
2017-05-19 06:36:13 +00:00
|
|
|
|
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
|
|
|
|
);
|
2017-05-19 06:36:13 +00:00
|
|
|
|
|
|
|
export default function storage({ store }) {
|
|
|
|
observe(store, getSelectedTab, tab => {
|
2020-05-06 02:19:55 +00:00
|
|
|
if (tab.server) {
|
2017-05-19 06:36:13 +00:00
|
|
|
saveTab(tab);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|