You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to popular demand for BTR/SSR solutions, as an alternate approach to using the html tagged template literal this issue outlines the use of a declarative syntax template resolver.
The resolver would require an async approach to resolving and attaching the template. This will require a few pieces, the first is the declarative HTML syntax. Once this has been declared on the page for the custom element, it will be added to the element's definition. This template syntax is meant to be able to be interpreted both by JavaScript in the browser, as well as by other languages during BTR/SSR, thus for applying values to create HTML from the template, where JavaScript is not applied we will use JSON and simple data structures.
Below will be an example, as you can see, for browser specific behavior we will keep a JavaScript-like syntax such as with the @click event.
Example HTML:
<f-templatename="my-custom-element"><template><button@click="{{ x.handleClick() }}" ?disabled="{{ x.disabled}} ">
{{ x.greeting }}
</button><input:value="{{ x.value }}"
><f-whenvalue="{{ x.hasFriends }}"><!--we assume the value passed to the condition is a boolean--><ul><f-repeatitems="{{ friend in x.friends }}"><!--we assume the items is an array, in this case it might be ["brenda", "james"]--><li>{{ friend.firstname }} {{ friend.lastname }}</li><!--this now takes the a new context of the individual array item, so this might render as "brenda"--></f-repeat></ul></f-when><f-slotteditems="{{ x.items }}"><slot></slot></f-slotted></template></f-template>
The reason that all directives are tags is because they should be made optional to allow for lighter bundles. If you don't use <f-when> (for example) you can choose not to include it.
This syntax is a close mirroring of how html template uses directives etc. so as not to confuse current consumers of html tagged template literal. We recognize that there are current efforts to create a standard for declarative HTML, but as they have not passed any meaningful stage at this time we will wait until the platforms proceed with a solution before we consider convergence.
One issue with declarative HTML is that we will not be interpreting any JavaScript, the developers will not be able to do anything like the following: <f-when condition="x.friends.length > 0">. This limitation means that we will only allow a variable that will be assumed to be a boolean.
Anything in the JSON data structure is assumed to be either an @attr or property of the custom element class. Therefore, hasFriends for example could be an observed property or a reflected attribute that is assigned in the constructor.
Aspected Attributes
Aspected attributes such as click events, property bindings, and boolean attributes can be represented in a 2 ways, either with a dataset attribute, or if XML 1.0 compliance is not required, with the same syntax as that offered by the html tag template literal. The "fe" identifies the dataset attribute as an event, likewise "fb" is for booleans, and "fp" is for properties.
dataset attribute:
<divdata-fe_click="{{ handleClick() }}" data-fb_disabled="{{ disabled }}" data-fp_value="{{ value }}"></div>
html tag template syntax:
<div@click="{{ handleClick() }}" ?disabled="{{ disabled }}" :value="{{ value }}"></div>
Directives
Directives may be represented either with elements or as attributes on elements.
Elements:
<f-whenvalue="{{ !disabled }}"><ul></ul></f-when>
Attributes:
<ulf-when="{{ !disabled }}"></ul>
Scoping
Scoping depending on configuration should either accept all values as the parent scope or should allow one scope up. Further scoping may be passed down by specific ID.
Additional scoping is applied during f-repeat directives:
<f-repeatitems="{{ item in items }}"></f-repeat>
Declarative HTML Template resolver
The second piece is the interpretation by a resolver to provide the ViewTemplate. This should be located on a different export path, per #7036 compose step example.
HTML Rendering
Fully documented examples with explanations will be provided to ensure processing of a Declarative HTML template is understood and can be resolved. FAST expects certain additions to the HTML for it to be hydratable, that includes comments etc.
In a build/server environment the HTML generation should work as follows:
flowchart TD
A[Declarative HTML Template]
B[FAST BTR Rust Implementation]
C[JSON state]
D[HTML]
E[Browser]
A --> B
C --> B
B --> D
D --> E
Loading
After the HTML has been loaded, the developer can choose when the <f-template> logic and HTML should be added, typically we would expect the following flow:
flowchart TD
Z[The page including BTR HTML is recieved from the server]
Y[TTVR complete]
A[The declarative HTML template is included in the DOM]
B[The <code>f-template</code> custom element is imported]
C[The <code>f-template</code> custom element creates a <code>ViewTemplate</code>]
D[The <code>ViewTemplate</code> is added as a template to existing FAST Custom Elements]
E[The FAST Custom Elements with this template hydrates & becomes interactable]
A --> C
B --> C
C --> D
D --> E
Y --> A
Y --> B
Z --> Y
Loading
The text was updated successfully, but these errors were encountered:
# Pull Request
## 📖 Description
This adds a simple binding, per #7037 to facilitate playwright testing.
## 👩💻 Reviewer Notes
This is some simple scaffolding, no code we intend to ship is in here but this will make future PRs cleaner as they won't include unrelated changes.
## ✅ Checklist
### General
<!--- Review the list and put an x in the boxes that apply. -->
- [ ] I have included a change request file using `$ npm run change`
- [ ] I have added tests for my changes.
- [x] I have tested my changes.
- [x] I have updated the project documentation to reflect my changes.
- [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
# Pull Request
## 📖 Description
This adds a simple binding, per #7037 to facilitate playwright testing.
## 👩💻 Reviewer Notes
This is some simple scaffolding, no code we intend to ship is in here but this will make future PRs cleaner as they won't include unrelated changes.
## ✅ Checklist
### General
<!--- Review the list and put an x in the boxes that apply. -->
- [ ] I have included a change request file using `$ npm run change`
- [ ] I have added tests for my changes.
- [x] I have tested my changes.
- [x] I have updated the project documentation to reflect my changes.
- [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
Introduction
Due to popular demand for BTR/SSR solutions, as an alternate approach to using the
html
tagged template literal this issue outlines the use of a declarative syntax template resolver.Requires completion of #7036
Requirements
Declarative HTML Template Syntax
The resolver would require an async approach to resolving and attaching the template. This will require a few pieces, the first is the declarative HTML syntax. Once this has been declared on the page for the custom element, it will be added to the element's definition. This template syntax is meant to be able to be interpreted both by JavaScript in the browser, as well as by other languages during BTR/SSR, thus for applying values to create HTML from the template, where JavaScript is not applied we will use JSON and simple data structures.
Below will be an example, as you can see, for browser specific behavior we will keep a JavaScript-like syntax such as with the
@click
event.Example HTML:
The reason that all directives are tags is because they should be made optional to allow for lighter bundles. If you don't use
<f-when>
(for example) you can choose not to include it.html Tagged template version:
Example JSON:
This syntax is a close mirroring of how
html
template uses directives etc. so as not to confuse current consumers ofhtml
tagged template literal. We recognize that there are current efforts to create a standard for declarative HTML, but as they have not passed any meaningful stage at this time we will wait until the platforms proceed with a solution before we consider convergence.One issue with declarative HTML is that we will not be interpreting any JavaScript, the developers will not be able to do anything like the following:
<f-when condition="x.friends.length > 0">
. This limitation means that we will only allow a variable that will be assumed to be a boolean.Anything in the JSON data structure is assumed to be either an
@attr
or property of the custom element class. Therefore,hasFriends
for example could be an observed property or a reflected attribute that is assigned in the constructor.Aspected Attributes
Aspected attributes such as click events, property bindings, and boolean attributes can be represented in a 2 ways, either with a dataset attribute, or if XML 1.0 compliance is not required, with the same syntax as that offered by the
html
tag template literal. The "fe" identifies the dataset attribute as an event, likewise "fb" is for booleans, and "fp" is for properties.dataset attribute:
html
tag template syntax:Directives
Directives may be represented either with elements or as attributes on elements.
Elements:
Attributes:
Scoping
Scoping depending on configuration should either accept all values as the parent scope or should allow one scope up. Further scoping may be passed down by specific ID.
Current scope:
Parent scope:
Additional scoping is applied during
f-repeat
directives:Declarative HTML Template resolver
The second piece is the interpretation by a resolver to provide the
ViewTemplate
. This should be located on a different export path, per #7036 compose step example.HTML Rendering
Fully documented examples with explanations will be provided to ensure processing of a Declarative HTML template is understood and can be resolved. FAST expects certain additions to the HTML for it to be hydratable, that includes comments etc.
Example rendering:
What is the flow?
In a build/server environment the HTML generation should work as follows:
After the HTML has been loaded, the developer can choose when the
<f-template>
logic and HTML should be added, typically we would expect the following flow:The text was updated successfully, but these errors were encountered: