From 71c2fda6e4c9f342e1e341f5a61c9966ea4147de Mon Sep 17 00:00:00 2001 From: Jane Chu <7559015+janechu@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:13:51 -0800 Subject: [PATCH] Split architecture doc into multiple explainers --- .../fast-element/ARCHITECTURE.md | 136 ------------------ .../fast-element/ARCHITECTURE_FASTELEMENT.md | 63 ++++++++ ...CHITECTURE_HTML_TAGGED_TEMPLATE_LITERAL.md | 32 +++++ .../fast-element/ARCHITECTURE_INTRO.md | 10 ++ .../fast-element/ARCHITECTURE_OVERVIEW.md | 52 +++++++ .../fast-element/ARCHITECTURE_UPDATES.md | 11 ++ 6 files changed, 168 insertions(+), 136 deletions(-) delete mode 100644 packages/web-components/fast-element/ARCHITECTURE.md create mode 100644 packages/web-components/fast-element/ARCHITECTURE_FASTELEMENT.md create mode 100644 packages/web-components/fast-element/ARCHITECTURE_HTML_TAGGED_TEMPLATE_LITERAL.md create mode 100644 packages/web-components/fast-element/ARCHITECTURE_INTRO.md create mode 100644 packages/web-components/fast-element/ARCHITECTURE_OVERVIEW.md create mode 100644 packages/web-components/fast-element/ARCHITECTURE_UPDATES.md diff --git a/packages/web-components/fast-element/ARCHITECTURE.md b/packages/web-components/fast-element/ARCHITECTURE.md deleted file mode 100644 index 3b98cfc19af..00000000000 --- a/packages/web-components/fast-element/ARCHITECTURE.md +++ /dev/null @@ -1,136 +0,0 @@ -# Architecture - -This document explains various logical flows for how a `FASTElement` is composed, defined, rendered, and updated. - -## What is FASTElement? - -`FASTElement` is an extension of `HTMLElement` which makes use of Custom Element APIs native to the browser. It also supplies the following methods: - -- The `compose` method combines the Custom Element name, template, style, and other options to create the definition for the Custom Element. -- The `define` method makes use of the native Custom Element [`define()`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) to register the Custom Element with a Custom Element Registry. -- The `from` method allows the use of Customized Built-in elements, which extend from native elements such as `HTMLButtonElement`. - -### Creating a Custom Element from FASTElement - -A basic developer flow for defining a custom element looks like this: - -```mermaid -flowchart TD - A[Create a FASTElement web component by extending the FASTElement class] --> F - F[Compose with FASTElement.compose to include template and styles] --> G[Define the component in the browser with FASTElement.define] -``` - -Let's take a look at the compose step to see what the FAST architecture is doing at this stage. - -### Composing a Custom Element - -The `FASTElement.compose()` function creates a new `FASTElementDefinition`, which includes all metadata needed for the element (such as templates, attributes, and styles). The element definition is registered with the global `FAST` for re-use, and the `FASTElementDefinition` is returned. The resulting object can be retrieved via `ElementController.definition`. - -## A Custom Element in JavaScript sent to the Browser - -Let's step back from defining the Custom Element and consider what is happening when we import from the `@microsoft/fast-element` package. - -First, a global `FAST` property will be created if one does not already exist, typically in browser on the `window`. - -Additionally, when Custom Elements are included in a script a few things might happen even before a Custom Element gets detected by the browser. First, there are initial side effects caused by the use of decorators. These include the `attr` and `observable` decorators made available by the `@microsoft/fast-element` package. - -```mermaid -flowchart TD - A[The browser loads the JavaScript file containing FAST] - A --> B[The FAST global is added] - B --> C[Any defined observable decorators are added to the FAST global] - A --> D[Any defined attribute decorators are attached to the constructor of the FAST Custom Element] -``` - -### Pre-render Template - -The `html` tagged template function creates a `ViewTemplate` object via the `ViewTemplate.create()` method. This is then used during the `compose` step, before `FASTElement` is instantiated. - -During the `Compiler.compile()` method triggered by `ViewTemplate.create()` method, the following happens for each string: -- Factories with unique IDs are created for each tag template literal argument (or `TemplateValue`) which matches with the corresponding string -- A binding is created from the `TemplateValue` - -A resulting string using a `createHTML()` function is produced using the `HTMLDirective`s executed for each factory. The behavior is augmented by the previous string from the `html` tag template which determines the aspect if one exists, these aspects are the `@`, `:`, or other binding aspect attached to attributes. - -The `createHTML()` function utilizes a `Markup` attribute which is assigned to a factory's unique ID. The strings are concatenated and passed to a new `ViewTemplate` with all the factories (empty until one is assigned) that act as a dictionary with the unique IDs as the key to look up each factory once it has been created. The string this creates is injected into a `