From 5cb550b09dcc4ff3d0a512a24329ec81866a4028 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 6 Apr 2017 12:06:01 -0600 Subject: [PATCH] Remove Pane's subclassing of Model --- spec/workspace-spec.js | 4 ++-- src/pane.coffee | 51 +++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index f00a2c12f..fe15d56f2 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -936,7 +936,7 @@ describe('Workspace', () => { atom.workspace.open('sample.js', {pending: true, split: 'right'}).then(o => { editor1 = o rightPane = atom.workspace.getActivePane() - spyOn(rightPane, 'destroyed') + spyOn(rightPane, 'destroy').andCallThrough() }) ) @@ -953,7 +953,7 @@ describe('Workspace', () => { runs(() => { expect(rightPane.getPendingItem()).toBe(editor2) - expect(rightPane.destroyed.callCount).toBe(0) + expect(rightPane.destroy.callCount).toBe(0) }) }) }) diff --git a/src/pane.coffee b/src/pane.coffee index b56f4e053..41bed59ee 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -1,11 +1,12 @@ Grim = require 'grim' {find, compact, extend, last} = require 'underscore-plus' {CompositeDisposable, Emitter} = require 'event-kit' -Model = require './model' PaneAxis = require './pane-axis' TextEditor = require './text-editor' PaneElement = require './pane-element' +nextInstanceId = 1 + # Extended: A container for presenting content in the center of the workspace. # Panes can contain multiple items, one of which is *active* at a given time. # The view corresponding to the active item is displayed in the interface. In @@ -16,7 +17,7 @@ PaneElement = require './pane-element' # simply being added. In the default configuration, the text in the tab for # pending items is shown in italics. module.exports = -class Pane extends Model +class Pane container: undefined activeItem: undefined focused: false @@ -40,14 +41,17 @@ class Pane extends Model })) constructor: (params) -> - super - { - @activeItem, @focused, @applicationDelegate, @notificationManager, @config, + @id, @activeItem, @focused, @applicationDelegate, @notificationManager, @config, @deserializerManager, @viewRegistry } = params + if @id? + nextInstanceId = Math.max(nextInstanceId, @id + 1) + else + @id = nextInstanceId++ @emitter = new Emitter + @alive = true @subscriptionsPerItem = new WeakMap @items = [] @itemStack = [] @@ -65,13 +69,15 @@ class Pane extends Model itemStackIndices = (itemsToBeSerialized.indexOf(item) for item in @itemStack when typeof item.serialize is 'function') activeItemIndex = itemsToBeSerialized.indexOf(@activeItem) - deserializer: 'Pane' - id: @id - items: itemsToBeSerialized.map((item) -> item.serialize()) - itemStackIndices: itemStackIndices - activeItemIndex: activeItemIndex - focused: @focused - flexScale: @flexScale + { + deserializer: 'Pane', + id: @id, + items: itemsToBeSerialized.map((item) -> item.serialize()) + itemStackIndices: itemStackIndices + activeItemIndex: activeItemIndex + focused: @focused + flexScale: @flexScale + } getParent: -> @parent @@ -759,16 +765,21 @@ class Pane extends Model @destroyItems() else @emitter.emit 'will-destroy' + @alive = false @container?.willDestroyPane(pane: this) - super + @container.activateNextPane() if @isActive() + @emitter.emit 'did-destroy' + @emitter.dispose() + item.destroy?() for item in @items.slice() + @container?.didDestroyPane(pane: this) - # Called by model superclass. - destroyed: -> - @container.activateNextPane() if @isActive() - @emitter.emit 'did-destroy' - @emitter.dispose() - item.destroy?() for item in @items.slice() - @container?.didDestroyPane(pane: this) + + isAlive: -> @alive + + # Public: Determine whether this pane has been destroyed. + # + # Returns a {Boolean}. + isDestroyed: -> not @isAlive() ### Section: Splitting