Skip to content

Move Observer Maps and declarative templates to the define method #7305

@janechu

Description

@janechu

Description

This would allow easier integration with FASTElement.

Solution

Using declarative templates

import { declarativeTemplate } from "@microsoft/fast-element/declarative.js";

class MyComponent extends FASTElement { }

MyComponent.define({
    name: "my-component",
    template: declarativeTemplate(), // returns a Promise<ViewTemplate>
});

Using declarative templates with Observer Maps

import { declarativeTemplate } from "@microsoft/fast-element/declarative.js";
import { observerMap } from "@microsoft/fast-element/augments/observer-map.js";

class MyComponent extends FASTElement { }

MyComponent.define({
    name: "my-component",
    template: declarativeTemplate(),
},
// code augmentations that are typically complex and have an opt-out style
// such as implicitly decorating a custom elements class for observation
// exist as a new additional argument to the .define call
[
    observerMap() // with declarative templates this will auto generate the JSON schema
]);

Using html tag template with Observer Maps

import { observerMap } from "@microsoft/fast-element/augments/observer-map.js";

class MyComponent extends FASTElement { }

MyComponent.define({
    name: "my-component",
    template: html`<div>${(x) => x.a}</div>`,
},
[
    observerMaps({ schemas: {
        "a": {}
    }}) // add JSON schemas manually since we cannot scan the html tag template
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeA breaking change to a shipping packageimprovementA non-feature-adding improvement

    Type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions