This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/stores/UiStore.js
2017-05-29 19:54:36 -07:00

35 lines
637 B
JavaScript

// @flow
import { observable, action, computed, autorunAsync } from 'mobx';
const UI_STORE = 'UI_STORE';
class UiStore {
@observable sidebar: boolean = false;
/* Computed */
@computed get asJson(): string {
return JSON.stringify({
sidebar: this.sidebar,
});
}
/* Actions */
@action toggleSidebar = (): void => {
this.sidebar = !this.sidebar;
};
constructor() {
// Rehydrate
const data = JSON.parse(localStorage.getItem(UI_STORE) || '{}');
this.sidebar = data.sidebar;
autorunAsync(() => {
localStorage.setItem(UI_STORE, this.asJson);
});
}
}
export default UiStore;