surplus icon indicating copy to clipboard operation
surplus copied to clipboard

Use with web components?

Open brody4hire opened this issue 7 years ago • 9 comments

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:

brody4hire avatar Jan 22 '18 04:01 brody4hire

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

brody4hire avatar Jan 22 '18 04:01 brody4hire

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.

adamhaile avatar Jan 28 '18 04:01 adamhaile

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

ismail-codar avatar Jan 28 '18 05:01 ismail-codar

Thanks Ismail, that looks super useful!

adamhaile avatar Jan 29 '18 03:01 adamhaile

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 avatar Jan 30 '18 01:01 adamhaile

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.

💯

adamhaile avatar Jan 30 '18 18:01 adamhaile

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

ismail-codar avatar Jan 30 '18 18:01 ismail-codar

Really awesome, thanks guys!

brody4hire avatar Jan 30 '18 18:01 brody4hire

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

adamhaile avatar Jan 31 '18 03:01 adamhaile