SlideShare a Scribd company logo
FRAMEWORKSANDWEBCOMPONENTS
friends or foes?
@filipbech
#alwaysHiring #Aarhus #Copenhagen
Frameworks and webcomponents
Frameworks and webcomponents
WRITEONCE-USEANYWHERE
the promise of webcomponents
Frameworks and webcomponents
THISTALKWILLBE
• Webcomponents - what and why
• How (basic tech intro)
• Using Webcomponents in your framework
• Your framework-component as a Web-component
WHY
• Interoperability - portability
• Native components brings us native performance
• Framework == implementation detail
ITS(FINALLY)HAPPENING…
SPECS
• custom elements
• shadow dom
• <template>
• es-modules
Frameworks and webcomponents
ATTRIBUTESVSPROPERTIES
Frameworks and webcomponents
Frameworks and webcomponents
CONTENTPROJECTIONWITHSLOT
NAMEDSLOTS
STYLING
• scoped to shadowRoot
• custom-properties
• special selectors - eg. :host, :slotted etc.
• ::parts on the horizon
WITHFRAMEWORKS
HOWTOUSEFROMWITHINFRAMEWORKS
• angular
• vue
• react (preact)
Frameworks and webcomponents
COMPARINGFEATURE-COMPLETENESS
• The tests checks that a framework supports the usage of custom elements
• Each test has an associated weight, based on how critical it is.The final tally
of pass/fails is combined with these weights to create a weighted average
score.
• Testing in browsers with native support AND in old browser with polyfill
• All credit goes to @rob_dodson
https://custom-elements-everywhere.com/
ANGULAR
Frameworks and webcomponents
Frameworks and webcomponents
https://custom-elements-everywhere.com/
VUE
Frameworks and webcomponents
https://custom-elements-everywhere.com/
REACT
Frameworks and webcomponents
https://custom-elements-everywhere.com/
Frameworks and webcomponents
REACT17MAYBE?
https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
PREACTTOTHERESCUE..?
https://custom-elements-everywhere.com/
Frameworks and webcomponents
SO…
• You can do it yourself
• Get a reference to the custom-element, and pass properties to it
• get a reference to the custom-element and addEventListener
YOURFRAMEWORK-COMPONENT
ASACUSTOM-ELEMENT
the why, the how and all the details
WHY
• Interoperability
• Framework is an implementation detail
• The component-developer chooses their preferred tools
• Write a datepicker in React - use it in an Angular form
HOW
• Native Webcomponent framework
• Wrap in custom-element
WRAPPING
• Element-properties for data
• Dom-events for events
• Slots
• Style encapsulation w. shadowDOM
THECOMPARISON
• features
• css encapsulation
• slots
• properties (inputs)
• events (outputs)
• ease of use (for dev)
• size of bundle
• NOT framework integration (too hard to compare)
EXPORTTOWEBCOMPONENTS
• Angular (official)
• Vue (official)
• React (community)
WHATAREWEBUILDING
• a custom-button component
• takes a label as a property
• Has a Slot for content
• counts clicks
• emits a custom event (“action”) when clicked
• contains an h1, and styles applied to h1
Frameworks and webcomponents
@ANGULAR/ELEMENTS
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
NG-CONTENTOR<SLOT>
Frameworks and webcomponents
Frameworks and webcomponents
ivy
Frameworks and webcomponents
IVYELEMENTS
• smaller, simpler, faster (~15kb)
• not in v8
• lazyNgElement
https://www.youtube.com/watch?v=JX5GGu_7JKc
@VUE/WEB-COMPONENT-WRAPPER
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
BUILDING
WITHVUE
• feels elegant and light
• e.detail is an array or additional arguments to $emit()
• Doesn’t handle styles => points to css-modules as the solution
• The bundle is tiny - but requires a global vue (cannot be tree-shaken)
Frameworks and webcomponents
REACT
REACTISDIFFERENT
• Passing callbacks as props instead of custom events
• CSS-in-JS
REACT…
• no official wrapper
• react-web-component
• web-react-components
• @adobe/react-webcomponent
• skateJS
WEB-REACT-COMPONENTS
• Looks like the real deal - but also not maintained
• Register()-method to wrap and register
• props.children is a <slot>
• Hack styles with <style dangerouslySetInnerHTML…>
• Requires the polyfill as it ships es5 😒
https://github.com/ChristophP/web-react-components
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
Frameworks and webcomponents
WEDON’THAVETIMEFOR
• @adobe/react-webcomponent
• skatejs
• something else
THERESULTSAREIN…
Angular Vue React
Consume 100 % 100 % 71 %
Wrap - features 😀 🙂 😕
Wrap - DX 🙂 😀 😀
Wrap - bundlesize ~50kb ~36kb ~39kb
DOWENEEDFRAMEWORKS
can we use webcomponents alone?
USINGWEBCOMPONENTSALONE
• Sugar on top
• LitElement, Stencil, Svelte,
• Helpers below
• Utility-libraries for http, state-management, etc…
https://developers.google.com/web/fundamentals/web-components/best-practices
THEPLATFORMSTILLHAVESOMEGAPS
• ::parts
• scoped registries
• import maps
• polyfilling is non-trivial
CONCLUSION
CONCLUSION
• Very interesting and promising future
• but it is still early days…
• Vue and Angular are good in using webcomponents. React not so much atm
• The wrappers are pretty cool, but incomplete, large and/or complex 

(and no official wrapper for react)
• <slot>’s don’t mix/match so well with framework-features
https://github.com/filipbech/framework-webcomponents
THANKYOU!
This was “frameworks and webcomponents”
Im @filipbech
Follow for slides

More Related Content

Frameworks and webcomponents