mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Fix bug where subviews could clobber outlets on superviews.
Now we wire outlets before the subviews are attached, preventing any outlets on the subview from overwriting outlets on the superview.
This commit is contained in:
@@ -8,13 +8,13 @@ describe "Template", ->
|
||||
subviewTemplate = class extends Template
|
||||
content: (params) ->
|
||||
@div =>
|
||||
@h2 params.title
|
||||
@h2 { outlet: "header" }, params.title
|
||||
@div "I am a subview"
|
||||
|
||||
template = class extends Template
|
||||
content: (attrs) ->
|
||||
@div =>
|
||||
@h1 attrs.title
|
||||
@h1 { outlet: 'header' }, attrs.title
|
||||
@list()
|
||||
@subview 'subview', subviewTemplate.build(title: "Subview")
|
||||
|
||||
@@ -52,6 +52,10 @@ describe "Template", ->
|
||||
expect(view.subview).toExist()
|
||||
expect(view.subview.find('h2:contains(Subview)')).toExist()
|
||||
|
||||
it "does not overwrite outlets on the superview with outlets from the subviews", ->
|
||||
expect(view.header).toMatchSelector "h1"
|
||||
expect(view.subview.header).toMatchSelector "h2"
|
||||
|
||||
it "binds events for elements with event name attributes", ->
|
||||
spyOn(view, 'li1Clicked').andCallFake (event, elt) ->
|
||||
expect(event.type).toBe 'click'
|
||||
|
||||
@@ -24,7 +24,6 @@ class Template
|
||||
@builder = new Builder
|
||||
@content(attributes)
|
||||
view = @builder.toFragment()
|
||||
@wireOutlets(view)
|
||||
@bindEvents(view)
|
||||
if @viewProperties
|
||||
$.extend(view, @viewProperties)
|
||||
@@ -39,12 +38,6 @@ class Template
|
||||
subview: (args...) ->
|
||||
@builder.subview.apply(@builder, args)
|
||||
|
||||
wireOutlets: (view) ->
|
||||
view.find('[outlet]').each ->
|
||||
elt = $(this)
|
||||
outletName = elt.attr('outlet')
|
||||
view[outletName] = elt
|
||||
|
||||
bindEvents: (view) ->
|
||||
for eventName in this.constructor.events
|
||||
view.find("[#{eventName}]").each ->
|
||||
|
||||
@@ -26,6 +26,7 @@ class Builder
|
||||
|
||||
toFragment: ->
|
||||
fragment = $(@toHtml())
|
||||
@wireOutlets fragment
|
||||
fn(fragment) for fn in @postProcessingFns
|
||||
fragment
|
||||
|
||||
@@ -63,6 +64,12 @@ class Builder
|
||||
text: (string) ->
|
||||
@document.push(new Text(string))
|
||||
|
||||
wireOutlets: (view) ->
|
||||
view.find('[outlet]').each ->
|
||||
elt = $(this)
|
||||
outletName = elt.attr('outlet')
|
||||
view[outletName] = elt
|
||||
|
||||
reset: ->
|
||||
@document = []
|
||||
@postProcessingFns = []
|
||||
|
||||
Reference in New Issue
Block a user