This is a prerelease version of FAST (3.0.0-rc.1).

@microsoft/fast-element > ElementController

ElementController class

Controls the lifecycle and rendering of a FASTElement.

Signature:

export declare class ElementController<TElement extends HTMLElement = HTMLElement> implements Notifier, HostController<TElement>

Implements: Notifier, HostController<TElement>

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ElementController class.

Properties

Property

Modifiers

Type

Description

behaviors

protected

Map<HostBehavior<TElement>, number> | null

The behaviors associated with the component.

context

readonly

ExecutionContext

The context the expression is evaluated against.

definition

readonly

FASTElementDefinition

The element definition that instructs this controller in how to handle rendering and other platform integrations.

hasExistingShadowRoot

protected

boolean

Indicates whether the element has an existing shadow root (e.g. from declarative shadow DOM).

isBound

readonly

boolean

Indicates whether the controller is bound.

isConnected

readonly

boolean

Indicates whether or not the custom element has been connected to the document.

isHydrated

readonly

Promise<boolean>

Resolves true after prerendered content has been successfully hydrated, or false when the component is client-side rendered or hydration is not enabled.

isPrerendered

readonly

Promise<boolean>

Resolves true when the element had an existing shadow root (from SSR or declarative shadow DOM) at connect time, false otherwise.

mainStyles

ElementStyles | null

The main set of styles used for the component, independent of any dynamically added styles.

needsInitialization

protected

boolean

Indicates whether the controller needs to perform initial rendering.

shadowOptions

ShadowRootOptions | undefined

The shadow root options for the component.

source

readonly

TElement

The element being controlled by this controller.

sourceLifetime

readonly

SourceLifetime | undefined

Indicates how the source's lifetime relates to the controller's lifetime.

stage

protected

Stages

The current lifecycle stage of the controller.

subject

readonly

TElement

The subject that subscribers will receive notifications for.

template

ElementViewTemplate<TElement> | null

Gets/sets the template used to render the component.

view

readonly

ElementView<TElement> | null

The view associated with the custom element.

Methods

Method

Modifiers

Description

addBehavior(behavior)

Adds the behavior to the component.

addStyles(styles)

Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.

bindObservables()

protected

Binds any observables that were set before upgrade.

captureBoundObservables()

protected

Captures own-properties that shadow observable accessors on the prototype so they can be rebound through the accessor before rendering.

connect()

Runs connected lifecycle behavior on the associated element.

connectBehaviors()

protected

Connects any existing behaviors on the associated element.

disconnect()

Runs disconnected lifecycle behavior on the associated element.

disconnectBehaviors()

protected

Disconnects any behaviors on the associated element.

emit(type, detail, options)

Emits a custom HTML event.

forCustomElement(element, override)

static

Locates or creates a controller for the specified element.

notify(args)

Notifies all subscribers of a property change.

observeLateAttributes()

protected

Observes late-defined attribute-map attributes that the platform does not surface through attributeChangedCallback because they were added after customElements.define() completed.

onAttributeChangedCallback(name, oldValue, newValue)

Runs the attribute changed callback for the associated element.

onUnbind(behavior)

Registers an unbind handler with the controller.

removeBehavior(behavior, force)

Removes the behavior from the component.

removeStyles(styles)

Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.

renderTemplate(template)

protected

Renders the provided template to the element.

setStrategy(strategy)

static

Sets the strategy that ElementController.forCustomElement uses to construct ElementController instances for an element.

subscribe(subscriber, propertyToWatch)

Subscribes to notification of changes in the element's state.

syncLateAttributes()

protected

Synchronizes late-defined attribute-map attributes from the live DOM to the associated property values before the initial render occurs.

unsubscribe(subscriber, propertyToUnwatch)

Unsubscribes from notification of changes in the element's state.