/* @flow */
/** @jsx etch.dom */

import etch from 'etch'
// $FlowBug: Yes, we know this isn't a React component :\
import DiffComponent from './diff-component'

import type DiffViewModel from './diff-view-model'

type DiffPaneItemComponentProps = {diffViewModel: DiffViewModel}

export default class DiffPaneItemComponent {
  diffViewModel: DiffViewModel;
  element: HTMLElement;
  refs: {diffComponent: HTMLElement};

  constructor (props: DiffPaneItemComponentProps) {
    this.acceptProps(props)
  }

  acceptProps ({diffViewModel}: DiffPaneItemComponentProps): Promise<void> {
    this.diffViewModel = diffViewModel

    let updatePromise = Promise.resolve()
    if (this.element) {
      updatePromise = etch.update(this)
    } else {
      etch.initialize(this)
    }

    this.element.addEventListener('focus', () => this.refs.diffComponent.focus())

    return updatePromise
  }

  update (props: DiffPaneItemComponentProps, children: Array<any>): Promise<void> {
    return this.acceptProps(props)
  }

  render () {
    return (
      <div className='pane-item' tabIndex='-1'>{
        <DiffComponent ref='diffComponent' diffViewModel={this.diffViewModel}/>
      }</div>
    )
  }
}

@@ -51,16 +51,69 @@
  'etch'%0A
+import %7BDisposable, CompositeDisposable%7D from 'atom'%0A
 // $Flow
@@ -464,16 +464,54 @@
 lement%7D;
+%0A  subscriptions: CompositeDisposable;
 %0A%0A  cons
@@ -565,33 +565,297 @@
    this.
-acceptProps(props
+subscriptions = new CompositeDisposable()%0A%0A    this.acceptProps(props)%0A%0A    const onFocus = () =%3E this.refs.diffComponent.focus()%0A    this.element.addEventListener('focus', onFocus)%0A    this.subscriptions.add(new Disposable(() =%3E this.element.removeEventListener('focus', onFocus))
 )%0A  %7D%0A%0A 
@@ -1128,91 +1128,8 @@
  %7D%0A%0A
-    this.element.addEventListener('focus', () =%3E this.refs.diffComponent.focus())%0A%0A
     
@@ -1457,11 +1457,110 @@
    )%0A  %7D
+%0A%0A  destroy (): Promise%3Cvoid%3E %7B%0A    this.subscriptions.dispose()%0A%0A    return etch.destroy(this)%0A  %7D
 %0A%7D%0A

Clean up the focus handler.