adamhaile / surplus

High performance JSX web views for S.js applications
639 stars 26 forks source link

Use with web components? #47

Open brodycj opened 6 years ago

brodycj commented 6 years ago

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 commented 6 years ago

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

adamhaile commented 6 years ago

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 commented 6 years ago

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

adamhaile commented 6 years ago

Thanks Ismail, that looks super useful!

adamhaile commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

brodycj commented 6 years ago

Really awesome, thanks guys!

adamhaile commented 6 years ago

Submitted a PR to add Surplus to custom-elements-everywhere: https://github.com/webcomponents/custom-elements-everywhere/pull/231