Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further wrap Polymer.dom(elem).children in Polymer.dom #2186

Closed
shashi opened this issue Aug 2, 2015 · 4 comments
Closed

Further wrap Polymer.dom(elem).children in Polymer.dom #2186

shashi opened this issue Aug 2, 2015 · 4 comments

Comments

@shashi
Copy link

shashi commented Aug 2, 2015

When you do Polymer.dom(elem).children, an array of light DOM children is obtained, but the elements are not further wrapped in Polymer.dom. I think this is a missed opportunity to completely mimic Shadow DOM-style tree scoping. A function that takes a root node and looks up a node down the tree will have to now be aware of wrapping all the children with Polymer.dom. (Same goes for functions that might use .parentNode, .firstChild and so on...)

Specifically the current behavior makes interop with DOM libraries such as virtual-dom more complicated than it should be (see discussion at Matt-Esch/virtual-dom#296).

Are there some arguments against this?

Thanks!

@shashi shashi changed the title Make Light DOM .children be Light DOM elements Further wrap Polymer.dom(elem).children in Polymer.dom Aug 2, 2015
@shashi
Copy link
Author

shashi commented Aug 3, 2015

Here is a Sneaky hack that lets me do this by wrapping a DomApi object in another parent type. https://gist.github.com/shashi/167eef348f268049460f

I don't know much about the performance impact of this, I wouldn't be surprised if this defeats the whole point of Shady DOM. I'd love to have someone review this piece of code.

@kevinpschaaf
Copy link
Member

We have an experimental layer in https://github.com/PolymerLabs/polymer-experiments/ that patches the DOM traversal API's (parent/children/childNodes, etc.) where needed for this exact case (interacting with other 3rd-party libs that don't know about Polymer.dom) that you should check out.

See https://github.com/PolymerLabs/polymer-experiments/blob/master/patch-dom.html#L12-L21

You basically just need to put this after your polymer.html import, e.g.:

<link rel="import" href="bower_components/polymer.html">
<link rel="import" href="bower_components/polymer-experiments/patch-dom.html">

Note, this may have negative performance implications (at the cost of more interoperability), and for the time being we definitely want users who are creating reusable components for others to consume to continue using Polymer.dom (so that the DOM patching layer doesn't become a de-facto requirement).

We are continuing to work on better framework interoperability, so watch this space.

@clintwood
Copy link

BIG 👍

@shashi
Copy link
Author

shashi commented Aug 6, 2015

I was able to work around this for my purposes with virtual-dom using a little more code than the gist above. I think I will avoid patch-dom.html since it is experimental and a lot of code I don't completely understand. Thanks @kevinpschaaf for the help though :) I'll look forward to better interoperability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants