FAST

repository·main·Indexed 27 days ago

https://github.com/microsoft/fast

An unopinionated system of components, development tools, and utilities for building enterprise-grade websites and applications. FAST focuses on native Web Components and modern Web Standards, including the microsoft-fast-build Rust crate for rendering declarative HTML templates with support for content bindings, conditional rendering via <f-when>, array iteration via <f-repeat>, and Declarative Shadow DOM output.

Tokens
264.4K
Snippets
830
Records
1.6K
Agent score
93%

What's inside microsoft-fast

  1. Overview of @microsoft/fast-element capabilities

    main
    @microsoft/fast-element is a lightweight library for building standards-based Custom Elements (Web Components). It provides tools for element authoring, reactive data binding, declarative templating, scoped styles, and dependency injection. The library is designed for client-side browser Window runtimes and relies on browser APIs like Custom Elements, Shadow DOM, and requestAnimationFrame for batched async updates.
  2. Overview of FAST and its core packages

    main

    FAST is a suite of tools designed for building reusable UI components using native Web Components and modern Web Standards. It is designed to be framework-agnostic and can be integrated incrementally into existing systems.

    Key packages include:

    • @microsoft/fast-element: A lightweight library for building performant, memory-efficient, and standards-compliant Web Components. It works in all major browsers and can be used with or without a front-end framework.
    • @fluentui/web-components: A library of ready-made Web Components based on the Fluent design language, built using @microsoft/fast-element.
  3. Understand the FASTElement lifecycle and runtime

    main

    The @microsoft/fast-element runtime is designed to run in the browser Window. It relies on native browser APIs including the Custom Element Registry, DOM, Shadow DOM, and requestAnimationFrame for rendering and update scheduling.

    Key Runtime Behaviors:

    • Global Property: A global FAST property is created on the window object if it does not already exist.
    • Decorators: Using decorators like @observable or @attr from @microsoft/fast-element triggers initial side effects during script execution. For example, @observable decorators are added to the FAST global, and @attr decorators locate the associated constructor to manage attribute collections.
    • Registration: The define() step registers the component with the Custom Element Registry, making it available for the browser to detect and initialize.
  4. Convert FAST templates to WebUI or TypeScript

    main

    microsoft-fast-convert is a tool designed to convert FAST declarative syntax into either WebUI prerelease HTML or FAST v3 TypeScript source.

    It accepts a single <f-template> string, validates the supported subset, and processes it through a conversion pipeline. The tool uses a hand scanner rather than a full HTML parser to maintain a lightweight dependency profile.

    Conversion Pipeline

    1. Parse Syntax: Determines if the target is webui-prerelease or fast-v3-ts.
    2. Validate: Ensures there is exactly one outer <f-template name="..."> tag.
    3. Extract: Pulls exactly one inner <template> element.
    4. Convert: Dispatches to the specific target converter.
  5. Understand the FAST Element Template Binding Pipeline

    main

    The FAST Element template binding system follows a five-stage pipeline to transform HTML templates into reactive DOM views:

    1. Template Authoring: Using the html tagged template to collect binding expressions and build HTML with placeholder markers.
    2. Compilation: The compiler parses the HTML into a DocumentFragment, walks the DOM tree, and records the target locations for each binding.
    3. View Creation: The compiled result clones the fragment and creates a targets object that maps each binding's unique ID to its specific DOM node.
    4. Binding (First Render): Factories create behaviors that attach to target nodes, such as adding event listeners, setting attributes, or observing expressions.
    5. Reactive Updates: When observed data changes, one-way binding observers notify their directive, which re-evaluates the expression and pushes the new value to the DOM via a "sink" function.
  6. Understand the focus of `fast-element`

    main
    fast-element is not designed as a monolithic Single Page Application (SPA) framework. Instead, its primary purpose is to enable the creation of Web Components. Because it focuses on the Web Component standard, you can use fast-element or any component built with it alongside other existing front-end frameworks (such as React, Vue, or Angular) rather than having to replace them.
  7. Understand Schema and Observer Map Architecture

    main

    The Schema and Observer Map architecture in @microsoft/fast-element enables automatic observation of complex, nested data objects (objects, arrays, and primitives) within FAST HTML templates.

    Key Components

    • Schema Class: Generates JSON schemas describing the structure and binding paths of data objects based on template analysis or manual registration.
    • Observer Map Class: Uses the schema to automatically define observable properties and create proxies for deep observation of nested objects.
    • f-template Integration: Automatically populates schemas and configures observer maps during template compilation.

    Supported Data Types

    • Objects: Nested structures with observable properties.
    • Arrays: Arrays with observable mutations and nested elements.
    • Primitives: String, number, and boolean values.

    Limitations

    This system does not handle:

    • Function bindings: Event handlers (e.g., @click="{handleClick()}") are treated as functions, not observable data.
    • Context paths: Bindings using the $c prefix (e.g., $c.parent.showNames) resolve from the ExecutionContext and are not part of the data model.
    • Computed expressions: Complex expressions evaluating to non-data values.
  8. Benefits of using Web Components with FAST

    main

    Web Components, the foundation of the FAST library, offer several advantages for application development:

    • Performance: Web Components typically provide faster startup times, better paint performance, lower memory usage, and smaller bundle sizes compared to many popular JavaScript frameworks (e.g., React, Angular, Vue).
    • Interoperability: Because every Web Component inherits from HTMLElement, they work seamlessly with any library or framework that interacts with the DOM, including React, Angular, Vue, and jQuery. This allows for a consistent design system across diverse application architectures.
    • Incremental Adoption: You can integrate Web Components into existing applications without a full rewrite. They function as custom extensions of the HTML palette and can be used alongside existing elements.
    • Future Compatibility: Web Components are part of the official HTML specification. Using them ensures compatibility with evolving web standards and platform improvements in the DOM and CSS.
    • Extensibility: Building an ecosystem or plugin model around Web Components allows users to choose their own preferred JavaScript framework, preventing framework lock-in.
    • Accessibility for Non-JS Developers: Web Components can be used by developers without deep JavaScript proficiency, as they can be manipulated using standard HTML patterns.
  9. Understand the relationship between `fast-element` and other frameworks

    main
    Unlike monolithic Single Page Application (SPA) frameworks, fast-element is designed specifically to enable the creation of Web Components. This architectural choice allows you to use fast-element or any component built on top of it alongside your existing favorite front-end framework (e.g., React, Vue, or Angular) rather than requiring you to replace it.
  10. Understand the FAST Element Updates API

    main

    The Updates API manages DOM work by batching updates to attributes, observables, and observed arrays. This work is processed asynchronously via a queue that is aligned with requestAnimationFrame in the browser Window runtime.

    Important Runtime Constraints:

    • FAST Element is designed for the client-side browser Window runtime.
    • It is not intended to run in Web Workers, server-side JavaScript runtimes (Node.js, etc.), or other non-window hosts.
    • For Server-Side Rendering (SSR), you should generate the HTML on the server and allow the browser to connect the custom elements and process the queued updates once it reaches the client.