Skip to content

Commit

Permalink
🎨 Move common logic into a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Steel Brain committed Feb 4, 2018
1 parent 5d29d04 commit 5694f14
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/panel/dock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ let React
let ReactDOM
let Component

// eslint-disable-next-line no-use-before-define
function getPaneContainer(item: PanelDock) {
const paneContainer = atom.workspace.paneContainerForItem(item)
// NOTE: This is an internal API access
// It's necessary because there's no Public API for it yet
if (paneContainer && typeof paneContainer.state === 'object' && typeof paneContainer.state.size === 'number' && typeof paneContainer.render === 'function') {
return paneContainer
}
return null
}

class PanelDock {
element: HTMLElement;
subscriptions: CompositeDisposable;
Expand All @@ -15,10 +26,8 @@ class PanelDock {
this.element = document.createElement('div')
this.subscriptions = new CompositeDisposable()
this.subscriptions.add(atom.config.observe('linter-ui-default.panelHeight', (panelHeight) => {
const paneContainer = atom.workspace.paneContainerForItem(this)
// NOTE: This is an internal API access
// It's necessary because there's no Public API for it yet
if (paneContainer && typeof paneContainer.state === 'object' && typeof paneContainer.state.size === 'number' && typeof paneContainer.render === 'function') {
const paneContainer = getPaneContainer(this)
if (paneContainer) {
paneContainer.state.size = panelHeight
paneContainer.render(paneContainer.state)
}
Expand Down Expand Up @@ -53,11 +62,9 @@ class PanelDock {
}
dispose() {
this.subscriptions.dispose()
const paneContainer = atom.workspace.paneContainerForItem(this)
const paneContainer = getPaneContainer(this)
if (paneContainer) {
if (typeof paneContainer.state === 'object' && typeof paneContainer.state.size === 'number') {
atom.config.set('linter-ui-default.panelHeight', paneContainer.state.size)
}
atom.config.set('linter-ui-default.panelHeight', paneContainer.state.size)
paneContainer.paneForItem(this).destroyItem(this, true)
}
}
Expand Down

0 comments on commit 5694f14

Please sign in to comment.