Palette
    Preparing search index...

    Interface ComponentShorthand<StateShape>

    interface ComponentShorthand<StateShape extends object = {}> {
        afterUpdate?: (
            this: Component<StateShape>,
            previousAttributes?: Record<string, string | null>,
        ) => void;
        beforeUpdate?: (
            this: Component<StateShape>,
            changedAttributes?: Record<string, string | null>,
        ) => void;
        finalize?: (this: Component<StateShape>) => void;
        initialState?:
            | StateShape
            | State<StateShape>
            | ((this: Component<StateShape>) => State<StateShape>)
            | ((this: Component<StateShape>) => StateShape);
        observedAttributes?: string[];
        onError?: (this: Component<StateShape>, error: unknown) => void;
        rootMode?: RootMode;
        script?: (this: Component<StateShape>) => void | VoidFunction;
        style?: string | CSSStyleSheet | CSSStyleSheet[];
        template?: HTMLTemplateElement;
        templateData?(
            this: Component<StateShape>,
            attributes?: Record<string, string | null>,
            state?: StateShape,
        ): Record<string, unknown>;
    }

    Type Parameters

    • StateShape extends object = {}
    Index

    Properties

    afterUpdate?: (
        this: Component<StateShape>,
        previousAttributes?: Record<string, string | null>,
    ) => void

    Called immediately after each template update

    beforeUpdate?: (
        this: Component<StateShape>,
        changedAttributes?: Record<string, string | null>,
    ) => void

    Called immediately before each template update

    finalize?: (this: Component<StateShape>) => void

    Called as the final lifecycle method at the end of the unmounting process.

    initialState?:
        | StateShape
        | State<StateShape>
        | ((this: Component<StateShape>) => State<StateShape>)
        | ((this: Component<StateShape>) => StateShape)

    The initial state for this Component.

    A plain object is deep-cloned for each instance. A State instance is shared by every instance (useful for stores). A function is called once per instance when it first connects.

    observedAttributes?: string[]

    Attributes to watch for changes for updates.

    onError?: (this: Component<StateShape>, error: unknown) => void

    If defined, receives errors caught during the lifecycle methods of this component and unhandled errors from its children. If not defined, errors escalate to the nearest ancestor component with an onError handler, and are thrown globally if there is none.

    rootMode?: RootMode

    The mode for this Component's ShadowRoot.

    MDN: https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/mode

    script?: (this: Component<StateShape>) => void | VoidFunction

    Initialization scripting for this Component

    style?: string | CSSStyleSheet | CSSStyleSheet[]

    Styles to encapsulate to this component's root.

    template?: HTMLTemplateElement

    An HTML Template element for this element to use.

    Methods

    • A function returning an object which populates the data values in the templating engine. Such values are accessed using the * notation.

      Called on every render with the host's current attributes and state.

      Parameters

      Returns Record<string, unknown>