2018-04-12 00:22:03 +03:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { stateToggler, shallowEqual } from "./helpers";
|
|
|
|
import * as storage from "./storage";
|
|
|
|
|
|
|
|
export default class extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = Object.assign(
|
|
|
|
{
|
2018-04-12 02:33:43 +03:00
|
|
|
showSidebar: false,
|
|
|
|
showAst: false,
|
|
|
|
showDoc: false,
|
|
|
|
toggleSidebar: () => this.setState(stateToggler("showSidebar")),
|
|
|
|
toggleAst: () => this.setState(stateToggler("showAst")),
|
|
|
|
toggleDoc: () => this.setState(stateToggler("showDoc"))
|
2018-04-12 00:22:03 +03:00
|
|
|
},
|
|
|
|
storage.get("editor_state")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(_, prevState) {
|
|
|
|
if (!shallowEqual(this.state, prevState)) {
|
|
|
|
storage.set("editor_state", this.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return this.props.children(this.state);
|
|
|
|
}
|
|
|
|
}
|