Options
All
  • Public
  • Public/Protected
  • All
Menu

Component that accepts a single promise and when it resolves, displays its content. If the promise is rejected, it throws the error out of its render method, which causes the error to propagate up the hierarchy to the nearest Boundary component. While the promise is pending, it displays whatever content was provided to it as children. Derived components can augment how the resolved content is displayed as well as how to react on promise rejection error.

Hierarchy

Index

Constructors

constructor

  • Awaiter is normally used as a managed component and thus is created by the Mimbl infrastructure and passed its properties.

    Parameters

    Returns Awaiter

Properties

Readonly isMounted

isMounted: boolean

Determines whether the component is currently mounted. If a component has asynchronous functionality (e.g. fetching data from a server), component's code may be executed after it was already unmounted. This property allows the component to handle this situation.

props

Component properties passed to the constructor. This is normally used only by managed components and is usually undefined for independent components.

Optional vn

Remembered virtual node object through which the component can request services. This is undefined in the component's costructor but will be defined before the call to the (optional) willMount method.

Accessors

displayName

  • get displayName(): string
  • String representation of the component

    Returns string

Methods

callMe

  • Schedules the given function to be called either before or after components update cycle.

    Parameters

    • func: ScheduledFuncType

      Function to be called

    • beforeUpdate: boolean

      If true, the function is called before the component updates cycle; if false - after the cycle.

    • Optional arg: any

      Argument that will be passed to the function.

    • Optional thisArg: any

      Object that will be used as "this" value when the function is called. If this parameter is undefined, the component instance will be used (which allows scheduling regular unbound components' methods). This parameter will be ignored if the function is already bound or is an arrow function.

    • Optional tickType: TickSchedulingType

      Defines whether and how Mimbl tick is scheduled after the function is called

    Returns void

fireEvent

  • Fires an event of the given type. The detail parameter is interpreted differently for built-in and custom events. For built-in events (that is, events whose type derives from Event), this is the event object itself. For custom events, it becomes the value of the detail property of the CustomEvent object.

    Type parameters

    • K: "resolved" | "rejected"

      Defines a range of possible values for the eventType parameter. K is a key from the TEvent type.

    Parameters

    • eventType: K

      Event type name, which is a key from the TEvents type

    • detail: AwaiterEvents[K]

      Event data, whose type is defined by the type mapped to the key in the TEvents type.

    Returns boolean

Protected getErrorContent

  • getErrorContent(err: any): any
  • This method can be overridden to provide content to display information about the given error. By default, the error is thrown and is supposed to propagate up to the nearest Boundary component.

    Parameters

    • err: any

      Promise rejection error.

    Returns any

Protected getResolvedContent

  • getResolvedContent(val: any): any
  • This method can be overridden to provide content to display for the resolved content. By default, the resolved value itself serves as the content.

    Parameters

    • val: any

      Promise's resolved value

    Returns any

    Content to rendered

getService

  • Retrieves the value for a service with the given ID registered by a closest ancestor component or the default value if none of the ancestor components registered a service with this ID. This method doesn't establish a subscription and only reflects the current state.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • Optional defaultValue: IServiceDefinitions[K]

      Default value to return if no publish service is found.

    • Optional useSelf: boolean

      Flag indicating whether the search for the service should start from the virtual node that calls this method. The default value is false meaning the search starts from the parent virtual node.

    Returns IServiceDefinitions[K]

    Current value of the service or default value if no published service is found.

publishService

  • Registers the given value as a service with the given ID that will be available for consumption by descendant components.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • value: IServiceDefinitions[K]

      Current value of the service

    • Optional depth: number

      Number of level to watch for changes. The default value is 1; that is, the subscribers will be notified if the service's value or the values of its properties have changed.

    Returns IPublication<K>

    Publication object, which allows setting a new value of the service or changing values of its properties.

subscribeService

  • Subscribes to a service with the given ID. If the service with the given ID is registered by this or one of the ancestor components, the returned subscription object's value property will reference it; otherwise, the value will be set to the defaultValue (if specified) or will remain undefined. Whenever the value of the service that is registered by this or a closest ancestor component is changed, the subscription's value property will receive the new value.

    If the subscription object's value property is used in a component's rendering code, the component will be re-rendered every time the service value is changed.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • Optional defaultValue: IServiceDefinitions[K]

      Optional default value that will be assigned if the service is not published yet.

    • Optional useSelf: boolean

      Flag indicating whether the search for the service should start from the virtual node that calls this method. The default value is false meaning the search starts from the parent virtual node.

    Returns ISubscription<K>

    Subscription object, which provides the value of the service and allowes attaching to the event fired when the value is changed.

updateMe

  • updateMe(): void
  • This method is called by the component to request to be updated.

    Returns void

wrap

  • Type parameters

    • T: Function

    Parameters

    • func: T

      Callback function to be wrapped

    • Optional arg: any

      Optional argument to be passed to the callback in addition to the original callback arguments.

    • Optional thisArg: any

      Optional object to be used as this when calling the callback. If this parameter is not defined, the component instance is used, which allows wrapping regular unbound components' methods. This parameter will be ignored if the the function is already bound or is an arrow function.

    • Optional schedulingType: TickSchedulingType

      Type of scheduling the Mimbl tick after the callback function returns.

    Returns T

    Wrapped callback that will run the original callback in the proper context.