When the last pane is destroyed, null out the root and active pane

This commit is contained in:
Nathan Sobo
2014-01-10 11:22:19 -07:00
parent c69febd44d
commit 5e1e092650
2 changed files with 22 additions and 5 deletions

View File

@@ -66,6 +66,11 @@ describe "PaneContainerModel", ->
container = new PaneContainerModel(root: pane)
container.on 'surrendered-focus', surrenderedFocusHandler = jasmine.createSpy("surrenderedFocusHandler")
it "assigns null to the root and the activePane", ->
pane.destroy()
expect(container.root).toBe null
expect(container.activePane).toBe null
describe "if the pane is focused", ->
it "emits a 'surrendered-focus' event", ->
pane.focus()

View File

@@ -14,6 +14,8 @@ class PaneContainerModel extends Model
focusContext: null
activePane: null
previousRoot: null
@behavior 'activePaneItem', ->
@$activePane.flatMapLatest (activePane) -> activePane?.$activeItem
@@ -22,11 +24,7 @@ class PaneContainerModel extends Model
@focusContext ?= new FocusContext
@subscribe @$root, (root) =>
if root?
root.parent = this
root.container = this
@activePane ?= root if root instanceof PaneModel
@subscribe @$root, @onRootChanged
deserializeParams: (params) ->
@focusContext ?= params.focusContext ? new FocusContext
@@ -76,3 +74,17 @@ class PaneContainerModel extends Model
@activePane = panes[nextIndex]
else
@activePane = null
onRootChanged: (root) =>
@unsubscribe(@previousRoot) if @previousRoot?
@previousRoot = root
return unless root?
root.parent = this
root.container = this
if root instanceof PaneModel
@activePane ?= root
@subscribe root, 'destroyed', =>
@activePane = null
@root = null