Provide examples of using web components with bindings #1004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a bunch of integration specs that can serve as an example of using custom elements with our bindings library. This suppose to be the path of least resistance to get into component-based UI development wherever the complexity requires, still without switching to full fledged UI framework. Keeping things lightweight and using the platform as far as we can feasibly do.
Framework component vs web component
A framework's component (React, Vue) is not the same as Web component. A framework component mainly about separating knowledge/structure based on application domain. Web component is a set of different technologies that allow building reusable custom elements. Custom elements by themselves is also another particular API in the web platform that allows defining HTML elements with custom behavior. Dynamic behavior can be based on user events, changing attributes, etc. It can be anything inside of it, but the application of custom elements remains the same, anywhere. This is the important part of web components, comparing to a framework components.
We are going to use custom elements, Shadow DOM, and inertial to define what a custom component is. It is going to be a structure, a pattern we can follow to build isolated components based on our domain (e.g. smaller reusable parts of a large complex form).
Custom component and its lifecycle
Here's briefly the structure I've used in this PR:
HTML in JS syntax highlight
Now that we put HTML template directly in JS/TS file and it's not JSX, it becomes harder to work with the code, since it is just a template string in terms of JS. In this PR I tagged the templates with
html
so that it can trigger certain setups and IDEs to treat the contents of following string as HTML. It also works on GitHub! Not sure if vscode suppose to support this by default, but if not, you can use es6-string-html vscode extension to enable this feature.