rfc: add Declartive Bindings to fast-element #6914
Labels
area:fast-element
Pertains to fast-element
area:ssr
Pertains to SSR.
status:needs-investigation
Needs additional investigation
status:under-consideration
Issue is being reviewed by the team.
💬 RFC
Update FAST-Element Templating to understand declarative bindings
🔦 Context
I am proposing a new Web Architecture called "Build Time Rendering" BTR for short that combines the insights gained from integrating Islands, SSR, and SSG. BTR determines the rendering process in advance, guided by cues provided by the web application itself. A key feature of BTR is the introduction of a simplified streaming protocol. This protocol is language-agnostic, enabling web servers written in any programming language to deliver experiences akin to SSR, eliminating the dependency on Node.js.
BDR requires hints within your web application relating to conditionals, lists, and variables. During the post-build process, these hints facilitate the division of the initially rendered page into streamable segments. The server no longer requires Node.js, as its primary function becomes reading the protocol of these streamable chunks and writing to the stream.
Only three declarative bindings are needed to facilitate the BTR process in generating streamable chunks post build process. The client side JavaScript will use these bindings when it hydrates the DOM into each Web Component’s @observable decorator. These bindings adhere to the dot notation, thereby supporting any JSON/Object notations. Finally, the client will resume as it was.
At the end, zero JavaScript is needed for FCP since everything will be streamed in from server. JS will kick in after paint, to add resumability with Web Components to make them interactive.
Minimum Declarative Bindings needed
To make that BDR concept work for FAST Element, we need to introduce three attributes that FAST understands. Intentionally named it after fast nomenclature.
f-signal
The f-signal binding serves as a wrapper around a value, capable of alerting relevant consumers when the value undergoes a change.
In this example, the name class variable within the Web Component is assigned to the value "Default Name". Any mutation to this.name triggers an update in the corresponding DOM element.
f-when
The f-when binding is a conditional element that can toggle between true and false states.
In this instance, the active class variable within the Web Component is set to true. If the user alters this to false, the associated element ceases to be displayed. It supports these operators
'&&', '||', '!', '==', '>', '>=', '<', '<='
and supports object dot notations.f-repeat
The f-repeat binding represents an array of templates.
In the above example,
users
class variable in the Web Component is set to a list of names that it is set to what its current children are. Same as the other bindings, once mutated, the DOM mutates. I am still not strict on convention, thew-component
here just tells it what the web component for the children is, but it would be better if thef-repeat
was a list of objects, then we could reserve two keys (key, and component) so we could create dynamic components.💻 Examples
The following is a todo app, fully streamable, fully SSRable, requires 0 JS at start, and resumability happens after paint fast:
Prototype
I have created a micro (1.75KB) FAST Element framework which does this end to end. Please take a look at the repo https://github.com/mohamedmansour/build-time-rendering-js where end to end prototype showcases how this works.
The text was updated successfully, but these errors were encountered: