 
   getElement: ->
     @element ?= new PaneContainerElement().initialize(this, {views: @viewRegistry})
+
+  destroy: ->
+    @alive = false
+    @cancelStoppedChangingActivePaneItemTimeout()
+    pane.destroy() for pane in @getRoot().getPanes()
+    @subscriptions.dispose()
+    @emitter.dispose()
+
+  isAlive: -> @alive
+
+  isDestroyed: -> not @isAlive()
 
   serialize: (params) ->
     deserializer: 'PaneContainer'

  didDestroyPane: (event) ->
    @emitter.emit 'did-destroy-pane', event

  # Called by Model superclass when destroyed
  destroyed: ->
    @cancelStoppedChangingActivePaneItemTimeout()
    pane.destroy() for pane in @getRoot().getPanes()
    @subscriptions.dispose()
    @emitter.dispose()

  cancelStoppedChangingActivePaneItemTimeout: ->
    if @stoppedChangingActivePaneItemTimeout?
      clearTimeout(@stoppedChangingActivePaneItemTimeout)

PaneContainerElement = require './pane-container-element'

module.exports =
class PaneContainer
  serializationVersion: 1
  root: null
  stoppedChangingActivePaneItemDelay: 100
  stoppedChangingActivePaneItemTimeout: null

  constructor: (params) ->
    {@config, applicationDelegate, notificationManager, deserializerManager, @viewRegistry, @location} = params
    @emitter = new Emitter
    @subscriptions = new CompositeDisposable
    @itemRegistry = new ItemRegistry
    @alive = true

    @setRoot(new Pane({container: this, @config, applicationDelegate, notificationManager, deserializerManager, @viewRegistry}))
    @setActivePane(@getRoot())
