Component context.

Passed to component constructor as its only parameter.

Extends ContextValues interface. The values are provided by corresponding providers registered with perComponent and perComponent methods.

Type Parameters

  • T extends object = any

    A type of component.

Hierarchy

  • CxValues
  • SupplyPeer
    • ComponentContext

Properties

component: ComponentInstance<T>

A component instance.

It is an error accessing this property before the component is created, e.g. from inside of component constructor or component instantiation event receiver. A whenReady callback can be used to work this around.

componentType: ComponentClass<T>

Component class constructor.

connected: boolean

Whether the component's element is connected.

This becomes true right before whenConnected event is sent.

contentRoot: ContentRoot

Component content root.

This is a shorthand for requesting a content root from component context.

element: any

Custom element constructed for the component according to its type.

E.g. HTMLElement instance.

mounted: boolean

Whether the component is mounted to element.

onceConnected: OnEvent<[ComponentContext<T>]>

An OnEvent sender of component's element connection event.

The registered receiver is called when component's element is connected. E.g. when custom element's connectedCallback() method is called.

If connected already the receiver is called immediately.

onceReady: OnEvent<[ComponentContext<T>]>

An OnEvent sender of component readiness event.

The component is constructed shortly after context. So the component may not exist when requested inside component constructor or component instantiation event receiver. The registered receiver will be notified when the component is constructed.

If the component is constructed already, the receiver will be notified immediately.

onceSettled: OnEvent<[ComponentContext<T>]>

An OnEvent sender of component settlement event.

The registered receiver is called when component is settled. If settled already the receiver is called immediately.

readStatus: AfterEvent<[ComponentContext<T>]>

An AfterEvent keeper of component status.

Sends this context instance each time the component status changes.

ready: boolean

Whether the component is ready.

Set to true when component is available.

settled: boolean

Whether the component is settled.

Component settlement happens:

  • when settle method is called,
  • when component is mounted to element, or
  • when component's element is connected.

It is guaranteed that component settlement won't happen inside custom element's constructor. So the settlement event may be used e.g. to start DOM manipulations, as it is prohibited inside custom element constructor.

This becomes true right before whenSettled event is sent.

supply: Supply

An event supply that disposes component and its context when cut off.

Unmounts the mounted component.

For custom element the component may be reconstructed when element is connected to document or settled again.

updateState: StateUpdater

Updates component's state.

This is a shorthand for invoking a component state updater .

Type Param

A type of changed value.

Param

Changed value key.

Param

New value.

Param

Previous value.

whenConnected: OnEvent<[ComponentContext<T>]>

An OnEvent sender of single component's element connection event.

The registered receiver is called when component's element is connected. E.g. when custom element's connectedCallback() method is called.

If connected already the receiver is called immediately.

In contrast to onceConnected, cuts off the event supply after sending the first event.

whenReady: OnEvent<[ComponentContext<T>]>

An OnEvent sender of single component readiness event.

The component is constructed shortly after context. So the component may not exist when requested inside component constructor or component instantiation event receiver. The registered receiver will be notified when the component is constructed.

If the component is constructed already, the receiver will be notified immediately.

In contrast to onceReady, cuts off the event supply after sending the first event.

whenSettled: OnEvent<[ComponentContext<T>]>

An OnEvent sender of single component settlement event.

The registered receiver is called when component is settled. If settled already the receiver is called immediately.

In contrast to onceSettled, cuts off the event supply after sending the first event.

Methods

  • Obtains value of the given context entry.

    Returns

    Either context entry value, or a fallback one.

    Type Parameters

    • TValue

      Requested context value type.

    Parameters

    • entry: CxEntry<TValue, unknown>

      Context entry to obtain the value of.

    • Optional request: WithoutFallback<TValue>

      Context value request with fallback specified.

    Returns TValue

  • Obtains value of the given context entry, or returns a non-nullable fallback.

    Returns

    Either context entry value, or a fallback one.

    Type Parameters

    • TValue

      Requested context value type.

    Parameters

    • entry: CxEntry<TValue, unknown>

      Context entry to obtain the value of.

    • request: WithFallback<TValue>

      Context value request with fallback specified.

    Returns TValue

  • Obtains value of the given context entry, or returns a nullable fallback.

    Returns

    Either context entry value, or a fallback one.

    Throws

    CxReferenceError - If the target entry has no value and fallback one is not provided.

    Type Parameters

    • TValue

      Requested context value type.

    Parameters

    • entry: CxEntry<TValue, unknown>

      Context entry to obtain the value of.

    • Optional request: CxRequest<TValue>

      Context value request.

    Returns null | TValue

  • Returns DOM event producer for the given event type.

    Retrieves an event producer from component event dispatcher available in this context.

    Returns

    A producer of DOM event events of the given type.

    Type Parameters

    • TEvent extends Event<TEvent>

      DOM event type.

    Parameters

    • type: string

      An event type to listen for.

    Returns OnDomEvent<TEvent>

  • Settles component.

    Calling this method has no effect if component is settled already, when component is not ready yet, or custom element's constructor is not exited.

    Calling this method may trigger DOM manipulations (the latter is prohibited inside custom element's constructor). This may be desired for rendering optimizations. E.g. to render element's content before adding it to document.

    This method is called automatically when mounting component to element.

    Returns void

Generated using TypeDoc