Skip to content

Commit f026da9

Browse files
janechuCopilot
andcommitted
refactor: remove FASTElementTemplateInput
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bc78e98 commit f026da9

10 files changed

Lines changed: 56 additions & 17 deletions

packages/fast-element/DESIGN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ registry.
103103
- `onAttributeChangedCallback()` is the standard handler that processes attribute changes. During the prerendered bind, it is temporarily swapped to a no-op (see above) to avoid redundant processing of server-rendered attribute values.
104104
- Exposes `addBehavior` / `removeBehavior` for dynamic `HostBehavior` management (used by `ElementStyles`).
105105

106-
`FASTElementDefinition` wraps all the metadata for a custom element class: its tag name, template, styles, and observed attribute list. It is created by `FASTElement.compose()` (which returns `Promise<FASTElementDefinition>`, always resolving immediately) and registered globally via `fastElementRegistry`. `PartialFASTElementDefinition.template` may be either a concrete `ElementViewTemplate` or a `FASTElementTemplateResolver` function that receives the composed definition and returns the concrete template (sync or async). `FASTElement.define()` returns `Promise<TType>` — resolving immediately for complete definitions or definitions without an initial template, and resolving async template resolver functions only after extensions have had a chance to update the definition. `FASTElementDefinition.register()` returns `Promise<Function>` — resolving when a definition with the given name has been registered.
106+
`FASTElementDefinition` wraps all the metadata for a custom element class: its tag name, template, styles, and observed attribute list. It is created by `FASTElement.compose()` (which returns `Promise<FASTElementDefinition>`, always resolving immediately) and registered globally via `fastElementRegistry`. `PartialFASTElementDefinition.template` may be either a concrete `ElementViewTemplate<InstanceType<TType>>` or a `FASTElementTemplateResolver<TType>` function that receives the composed definition and returns the concrete template (sync or async). `FASTElementDefinition.template` always stores the concrete `ElementViewTemplate<InstanceType<TType>>` after composition or resolver settlement. `FASTElement.define()` returns `Promise<TType>` — resolving immediately for complete definitions or definitions without an initial template, and resolving async template resolver functions only after extensions have had a chance to update the definition. `FASTElementDefinition.register()` returns `Promise<Function>` — resolving when a definition with the given name has been registered.
107107

108108
#### Extensions
109109

packages/fast-element/docs/api-report.api.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class FASTElementDefinition<TType extends Constructable<HTMLElement> = Co
443443
readonly registry: CustomElementRegistry;
444444
shadowOptions?: ShadowRootOptions;
445445
readonly styles?: ElementStyles;
446-
template?: ElementViewTemplate;
446+
template?: ElementViewTemplate<InstanceType<TType>>;
447447
readonly type: TType;
448448
}
449449

@@ -734,8 +734,7 @@ export interface PartialFASTElementDefinition<TType extends Constructable<HTMLEl
734734
readonly registry?: CustomElementRegistry;
735735
readonly shadowOptions?: Partial<ShadowRootOptions> | null;
736736
readonly styles?: ComposableStyles | ComposableStyles[];
737-
// Warning: (ae-forgotten-export) The symbol "FASTElementTemplateInput" needs to be exported by the entry point index.d.ts
738-
readonly template?: FASTElementTemplateInput<TType>;
737+
readonly template?: ElementViewTemplate<InstanceType<TType>> | FASTElementTemplateResolver<TType>;
739738
}
740739

741740
// @public

packages/fast-element/src/components/element-controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ export class ElementController<TElement extends HTMLElement = HTMLElement>
227227
this._template = (this.source as any).resolveTemplate();
228228
} else if (definition.template) {
229229
// 3. Default to the static definition.
230-
this._template = definition.template ?? null;
230+
this._template =
231+
(definition.template as ElementViewTemplate<TElement> | undefined) ??
232+
null;
231233
}
232234
}
233235

packages/fast-element/src/components/fast-definitions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export type FASTElementTemplateResolver<
7474
| ElementViewTemplate<InstanceType<TType>>
7575
| Promise<ElementViewTemplate<InstanceType<TType>>>;
7676

77-
type FASTElementTemplateInput<
77+
type FASTElementTemplateSource<
7878
TType extends Constructable<HTMLElement> = Constructable<HTMLElement>,
7979
> = ElementViewTemplate<InstanceType<TType>> | FASTElementTemplateResolver<TType>;
8080

@@ -96,7 +96,7 @@ const extensionRegistries = new WeakMap<
9696
function isFASTElementTemplateResolver<
9797
TType extends Constructable<HTMLElement> = Constructable<HTMLElement>,
9898
>(
99-
value: FASTElementTemplateInput<TType> | undefined,
99+
value: FASTElementTemplateSource<TType> | undefined,
100100
): value is FASTElementTemplateResolver<TType> {
101101
return isFunction(value);
102102
}
@@ -239,7 +239,9 @@ export interface PartialFASTElementDefinition<
239239
/**
240240
* The template, or template resolver, for the custom element.
241241
*/
242-
readonly template?: FASTElementTemplateInput<TType>;
242+
readonly template?:
243+
| ElementViewTemplate<InstanceType<TType>>
244+
| FASTElementTemplateResolver<TType>;
243245

244246
/**
245247
* The styles to associate with the custom element.
@@ -321,7 +323,7 @@ export class FASTElementDefinition<
321323
/**
322324
* The template to render for the custom element.
323325
*/
324-
public template?: ElementViewTemplate;
326+
public template?: ElementViewTemplate<InstanceType<TType>>;
325327

326328
/**
327329
* The styles to associate with the custom element.

sites/website/src/docs/3.x/api/fast-element.fastelementdefinition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ _(Optional)_ The styles to associate with the custom element.
352352

353353
</td><td>
354354

355-
[ElementViewTemplate](../fast-element.elementviewtemplate/)
355+
[ElementViewTemplate](../fast-element.elementviewtemplate/)<!-- -->&lt;InstanceType&lt;TType&gt;&gt;
356356

357357

358358
</td><td>

sites/website/src/docs/3.x/api/fast-element.fastelementdefinition.template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ The template to render for the custom element.
2020
**Signature:**
2121

2222
```typescript
23-
template?: ElementViewTemplate;
24-
```
23+
template?: ElementViewTemplate<InstanceType<TType>>;
24+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
id: "fast-element.fastelementtemplateresolver"
3+
title: "FASTElementTemplateResolver type"
4+
layout: 3x-api
5+
eleventyNavigation:
6+
key: "api3xfast-element.fastelementtemplateresolver"
7+
parent: "api3xfast-element"
8+
title: "FASTElementTemplateResolver type"
9+
navigationOptions:
10+
activeKey: "api3xfast-element.fastelementtemplateresolver"
11+
---
12+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
13+
14+
[@microsoft/fast-element](../fast-element/index.html) &gt; [FASTElementTemplateResolver](../fast-element.fastelementtemplateresolver/index.html)
15+
16+
## FASTElementTemplateResolver type
17+
18+
Resolves an element template from a composed definition.
19+
20+
**Signature:**
21+
22+
```typescript
23+
export type FASTElementTemplateResolver<TType extends Constructable<HTMLElement> = Constructable<HTMLElement>> = (definition: FASTElementDefinition<TType>) => ElementViewTemplate<InstanceType<TType>> | Promise<ElementViewTemplate<InstanceType<TType>>>;
24+
```
25+
**References:** [Constructable](../fast-element.constructable/), [FASTElementDefinition](../fast-element.fastelementdefinition/), [ElementViewTemplate](../fast-element.elementviewtemplate/)

sites/website/src/docs/3.x/api/fast-element.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,17 @@ The signature of an arrow function capable of being evaluated against source dat
17061706
A callback that receives a FASTElementDefinition during element registration. Extensions are invoked before the element is registered with the platform, allowing plugins to inspect or act on the resolved definition.
17071707

17081708

1709+
</td></tr>
1710+
<tr><td>
1711+
1712+
[FASTElementTemplateResolver](../fast-element.fastelementtemplateresolver/)
1713+
1714+
1715+
</td><td>
1716+
1717+
Resolves an element template from a composed definition.
1718+
1719+
17091720
</td></tr>
17101721
<tr><td>
17111722

sites/website/src/docs/3.x/api/fast-element.partialfastelementdefinition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ _(Optional)_ The styles to associate with the custom element.
205205

206206
</td><td>
207207

208-
[ElementViewTemplate](../fast-element.elementviewtemplate/)
208+
[ElementViewTemplate](../fast-element.elementviewtemplate/)<!-- -->&lt;InstanceType&lt;TType&gt;&gt; | [FASTElementTemplateResolver](../fast-element.fastelementtemplateresolver/)<!-- -->&lt;TType&gt;
209209

210210

211211
</td><td>
212212

213-
_(Optional)_ The template to render for the custom element.
213+
_(Optional)_ The template, or template resolver, for the custom element.
214214

215215

216216
</td></tr>

sites/website/src/docs/3.x/api/fast-element.partialfastelementdefinition.template.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ navigationOptions:
1515

1616
## PartialFASTElementDefinition.template property
1717

18-
The template to render for the custom element.
18+
The template, or template resolver, for the custom element.
1919

2020
**Signature:**
2121

2222
```typescript
23-
readonly template?: ElementViewTemplate;
24-
```
23+
readonly template?: ElementViewTemplate<InstanceType<TType>> | FASTElementTemplateResolver<TType>;
24+
```

0 commit comments

Comments
 (0)