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

Use with web components? #47

Open
brodycj opened this issue Jan 22, 2018 · 9 comments
Open

Use with web components? #47

brodycj opened this issue Jan 22, 2018 · 9 comments

Comments

@brodycj
Copy link
Contributor

brodycj commented Jan 22, 2018

I am curious if anyone thought about how this wonderful library might be used with custom elements, etc. I am thinking in comparison to react, as in a few articles I found:

@brodycj
Copy link
Contributor Author

brodycj commented Jan 22, 2018

Also any ideas for higher level app components analogous to https://github.com/lastmjs/redux-store-element?

@adamhaile
Copy link
Owner

I have to admit that I haven't explored web components beyond some tinkering. At a first glance, I think they'll integrate reasonably easily with Surplus since Surplus creates native DOM nodes (no middle layer to negotiate). Right now I'm mostly working on solidifying SVG support but hope to look at web components after that.

@ismail-codar
Copy link
Contributor

https://github.com/webcomponents/custom-elements-everywhere is good for testing.

@adamhaile
Copy link
Owner

Thanks Ismail, that looks super useful!

@adamhaile
Copy link
Owner

I cloned custom-elements-everywhere and added a surplus implementation. It shook loose one bug in surplus' codegen: we created bad identifiers for custom elements that had two dashes in their names due to a regex bug. After fixing that, surplus passes all of their "basic" web component tests. It fails some advanced ones because there's no framework support for declaratively subscribing to custom events. I.e., right now when you do <div onclick={...}></div>, the onclick parameter is no different from any property: you're just setting the .onclick property of the div. But that mechanism doesn't work for custom elements, as there's no .onMySpecialEvent property.

I could add compiler support to convert setting .onclick to node.addEventListener('click', ...), but I have to think about if that's a good idea. I wouldn't want to slow down the common cases to accomodate the corner case of custom events.

@adamhaile
Copy link
Owner

I resurrected a small utility for doing declarative custom event binding: https://github.com/adamhaile/surplus-mixin-on . It uses addEventListener() under the hood instead of the DOM node.on... properties. With it, Surplus gets a 100% score in custom-elements-everywhere tests on both Chrome and Firefox.

💯

@ismail-codar
Copy link
Contributor

It's nice not to lose speed. We are waiting it in the https://github.com/webcomponents/custom-elements-everywhere/tree/master/libraries

@brodycj
Copy link
Contributor Author

brodycj commented Jan 30, 2018

Really awesome, thanks guys!

@adamhaile
Copy link
Owner

Submitted a PR to add Surplus to custom-elements-everywhere: webcomponents/custom-elements-everywhere#231

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