Skip to content

Commit

Permalink
Change ::setModel to ::initialize on all element classes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld authored and Nathan Sobo committed Dec 2, 2014
1 parent 4591f00 commit e4bcb96
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 19 deletions.
4 changes: 3 additions & 1 deletion spec/panel-container-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ describe "PanelContainerElement", ->
class TestPanelContainerItemElement extends HTMLElement
createdCallback: ->
@classList.add('test-root')
setModel: (@model) ->
initialize: (@model) ->
this

TestPanelContainerItemElement = document.registerElement 'atom-test-container-item-element', prototype: TestPanelContainerItemElement.prototype

beforeEach ->
Expand Down
4 changes: 3 additions & 1 deletion spec/panel-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe "PanelElement", ->
class TestPanelItemElement extends HTMLElement
createdCallback: ->
@classList.add('test-root')
setModel: (@model) ->
initialize: (@model) ->
this

TestPanelItemElement = document.registerElement 'atom-test-item-element', prototype: TestPanelItemElement.prototype

beforeEach ->
Expand Down
2 changes: 1 addition & 1 deletion spec/workspace-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ describe "Workspace", ->

class TestItemElement extends HTMLElement
constructor: ->
setModel: (@model) ->
initialize: (@model) -> this
getModel: -> @model

beforeEach ->
Expand Down
3 changes: 2 additions & 1 deletion src/pane-axis-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PaneAxisElement extends HTMLElement
detachedCallback: ->
@subscriptions.dispose()

setModel: (@model) ->
initialize: (@model) ->
@subscriptions.add @model.onDidAddChild(@childAdded.bind(this))
@subscriptions.add @model.onDidRemoveChild(@childRemoved.bind(this))
@subscriptions.add @model.onDidReplaceChild(@childReplaced.bind(this))
Expand All @@ -20,6 +20,7 @@ class PaneAxisElement extends HTMLElement
@classList.add('horizontal', 'pane-row')
when 'vertical'
@classList.add('vertical', 'pane-column')
this

childAdded: ({child, index}) ->
view = atom.views.getView(child)
Expand Down
3 changes: 2 additions & 1 deletion src/pane-container-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class PaneContainerElement extends HTMLElement
PaneContainerView ?= require './pane-container-view'
@__spacePenView = new PaneContainerView(this)

setModel: (@model) ->
initialize: (@model) ->
@subscriptions.add @model.observeRoot(@rootChanged.bind(this))
@__spacePenView.setModel(@model)
this

rootChanged: (root) ->
focusedElement = document.activeElement if @hasFocus()
Expand Down
7 changes: 4 additions & 3 deletions src/pane-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ class PaneElement extends HTMLElement
createSpacePenShim: ->
@__spacePenView = new PaneView(this)

getModel: -> @model

setModel: (@model) ->
initialize: (@model) ->
@subscriptions.add @model.onDidActivate(@activated.bind(this))
@subscriptions.add @model.observeActive(@activeStatusChanged.bind(this))
@subscriptions.add @model.observeActiveItem(@activeItemChanged.bind(this))
@subscriptions.add @model.onDidRemoveItem(@itemRemoved.bind(this))
@subscriptions.add @model.onDidDestroy(@paneDestroyed.bind(this))
@__spacePenView.setModel(@model)
this

getModel: -> @model

activated: ->
@focus()
Expand Down
7 changes: 4 additions & 3 deletions src/panel-container-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ class PanelContainerElement extends HTMLElement
createdCallback: ->
@subscriptions = new CompositeDisposable

getModel: -> @model

setModel: (@model) ->
initialize: (@model) ->
@subscriptions.add @model.onDidAddPanel(@panelAdded.bind(this))
@subscriptions.add @model.onDidRemovePanel(@panelRemoved.bind(this))
@subscriptions.add @model.onDidDestroy(@destroyed.bind(this))
@classList.add(@model.getLocation())
this

getModel: -> @model

panelAdded: ({panel, index}) ->
panelElement = atom.views.getView(panel)
Expand Down
7 changes: 4 additions & 3 deletions src/panel-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class PanelElement extends HTMLElement
createdCallback: ->
@subscriptions = new CompositeDisposable

getModel: -> @model

setModel: (@model) ->
initialize: (@model) ->
@appendChild(@getItemView())

@classList.add(@model.getClassName().split(' ')...) if @model.getClassName()?
@subscriptions.add @model.onDidChangeVisible(@visibleChanged.bind(this))
@subscriptions.add @model.onDidDestroy(@destroyed.bind(this))
this

getModel: -> @model

getItemView: ->
atom.views.getView(@model.getItem())
Expand Down
6 changes: 5 additions & 1 deletion src/text-editor-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class TextEditorElement extends HTMLElement
@component.checkForVisibilityChange()
@focus() if @focusOnAttach

initialize: (model) ->
@setModel(model)
this

setModel: (model) ->
throw new Error("Model already assigned on TextEditorElement") if @model?
return if model.isDestroyed()
Expand All @@ -70,8 +74,8 @@ class TextEditorElement extends HTMLElement
@mountComponent()
@addGrammarScopeAttribute()
@addMiniAttributeIfNeeded()
@model.onDidChangeGrammar => @addGrammarScopeAttribute()
@addEncodingAttribute()
@model.onDidChangeGrammar => @addGrammarScopeAttribute()
@model.onDidChangeEncoding => @addEncodingAttribute()
@model.onDidDestroy => @unmountComponent()
@__spacePenView.setModel(@model)
Expand Down
2 changes: 1 addition & 1 deletion src/view-registry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ViewRegistry
element = provider.createView?(object)
unless element?
element = new provider.viewConstructor
element.setModel(object)
element.initialize?(object) ? element.setModel?(object)
element
else if viewConstructor = object?.getViewClass?()
view = new viewConstructor(object)
Expand Down
7 changes: 4 additions & 3 deletions src/workspace-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class WorkspaceElement extends HTMLElement
WorkspaceView ?= require './workspace-view'
@__spacePenView = new WorkspaceView(this)

getModel: -> @model

setModel: (@model) ->
initialize: (@model) ->
@paneContainer = atom.views.getView(@model.paneContainer)
@verticalAxis.appendChild(@paneContainer)
@addEventListener 'focus', @handleFocus.bind(this)
Expand All @@ -85,6 +83,9 @@ class WorkspaceElement extends HTMLElement
@appendChild(@panelContainers.modal)

@__spacePenView.setModel(@model)
this

getModel: -> @model

setTextEditorFontSize: (fontSize) ->
@updateGlobalEditorStyle('font-size', fontSize + 'px')
Expand Down

0 comments on commit e4bcb96

Please sign in to comment.