import {ComponentRegistry, WorkspaceStore, Actions} from "nylas-exports" import {RetinaImg} from 'nylas-component-kit' import React from "react" import _ from "underscore" export default class ModeToggle extends React.Component { static displayName = 'ModeToggle'; constructor(props) { super(props); this.column = WorkspaceStore.Location.MessageListSidebar this.state = this._getStateFromStores() } componentDidMount() { this._unsubscriber = WorkspaceStore.listen(this._onStateChanged) this._mounted = true; } componentWillUnmount() { this._mounted = false if (this._unsubscriber) { this._unsubscriber(); } } _getStateFromStores() { return { hidden: WorkspaceStore.isLocationHidden(this.column), }; } _onStateChanged = () => { // We need to keep track of this because our parent unmounts us in the same // event listener cycle that we receive the event in. ie: // // for listener in listeners // # 1. workspaceView remove left column // # ---- Mode toggle unmounts, listeners array mutated in place // # 2. ModeToggle update if (!this._mounted) { return; } this.setState(this._getStateFromStores()); } _onToggleMode = () => { Actions.toggleWorkspaceLocationHidden(this.column) } render() { return ( ); } }