Merge pull request #8431 from atom/tj-improve-etch-support

Extend ViewRegistry with support for objects with an element property
This commit is contained in:
Nathan Sobo
2015-08-18 15:10:30 -06:00
2 changed files with 10 additions and 0 deletions

View File

@@ -26,6 +26,14 @@ describe "ViewRegistry", ->
expect(node.textContent).toBe "Hello"
expect(node.spacePenView).toBe view
describe "when passed an object with an element property", ->
it "returns the element property if it's an instance of HTMLElement", ->
class TestComponent
constructor: -> @element = document.createElement('div')
component = new TestComponent
expect(registry.getView(component)).toBe component.element
describe "when passed a model object", ->
describe "when a view provider is registered matching the object's constructor", ->
it "constructs a view element and assigns the model on it", ->

View File

@@ -138,6 +138,8 @@ class ViewRegistry
createView: (object) ->
if object instanceof HTMLElement
object
else if object?.element instanceof HTMLElement
object.element
else if object?.jquery
object[0]
else if provider = @findProvider(object)