Class Application<T>

A class for creating pluggable applications.

Type Parameters

  • T extends Widget = Widget

    The type of the application shell.

    Notes

    The Application class is useful when creating large, complex UI applications with the ability to be safely extended by third party code via plugins.

Constructors

Properties

_bubblingKeydown: boolean = false
_delegate: PromiseDelegate<void> = ...
_started: boolean = false
commands: CommandRegistry

The application command registry.

contextMenu: ContextMenu

The application context menu.

pluginRegistry: PluginRegistry<any>

Application plugin registry.

shell: T

The application shell widget.

Notes

The shell widget is the root "container" widget for the entire application. It will typically expose an API which allows the application plugins to insert content in a variety of places.

Accessors

  • get started(): Promise<void>
  • A promise which resolves after the application has started.

    Notes

    This promise will resolve after the start() method is called, when all the bootstrapping and shell mounting work is complete.

    Returns Promise<void>

Methods

  • Activate all the deferred plugins.

    Returns Promise<void>

    A promise which will resolve when each plugin is activated or rejects with an error if one cannot be activated.

  • Activate the plugin with the given ID.

    Parameters

    • id: string

      The ID of the plugin of interest.

    Returns Promise<void>

    A promise which resolves when the plugin is activated or rejects with an error if it cannot be activated.

  • Add the application event listeners.

    Notes

    The default implementation of this method adds listeners for 'keydown' and 'resize' events.

    A subclass may reimplement this method as needed.

    Returns void

  • Attach the application shell to the DOM.

    Parameters

    • id: string

      The ID of the host node for the shell, or ''.

      Notes

      If the ID is not provided, the document body will be the host.

      A subclass may reimplement this method as needed.

    Returns void

  • Deactivate the plugin and its downstream dependents if and only if the plugin and its dependents all support deactivate.

    Parameters

    • id: string

      The ID of the plugin of interest.

    Returns Promise<string[]>

    A list of IDs of downstream plugins deactivated with this one.

  • Deregister a plugin with the application.

    Parameters

    • id: string

      The ID of the plugin of interest.

    • Optional force: boolean

      Whether to deregister the plugin even if it is active.

    Returns void

  • A method invoked on a document 'contextmenu' event.

    Notes

    The default implementation of this method opens the application contextMenu at the current mouse position.

    If the application context menu has no matching content or if the shift key is pressed, the default browser context menu will be opened instead.

    A subclass may reimplement this method as needed.

    Parameters

    Returns void

  • A method invoked on a document 'keydown' event.

    Notes

    The default implementation of this method invokes the key down processing method of the application command registry.

    A subclass may reimplement this method as needed.

    Parameters

    Returns void

  • A method invoked on a document 'keyup' event.

    Notes

    The default implementation of this method invokes the key up processing method of the application command registry.

    A subclass may reimplement this method as needed.

    Parameters

    Returns void

  • A method invoked on a window 'resize' event.

    Notes

    The default implementation of this method updates the shell.

    A subclass may reimplement this method as needed.

    Parameters

    Returns void

  • Get a plugin description.

    Parameters

    • id: string

      The ID of the plugin of interest.

    Returns string

    The plugin description.

  • Handle the DOM events for the application.

    Parameters

    • event: Event

      The DOM event sent to the application.

      Notes

      This method implements the DOM EventListener interface and is called in response to events registered for the application. It should not be called directly by user code.

    Returns void

  • Test whether a plugin is registered with the application.

    Parameters

    • id: string

      The ID of the plugin of interest.

    Returns boolean

    true if the plugin is registered, false otherwise.

  • Test whether a plugin is activated with the application.

    Parameters

    • id: string

      The ID of the plugin of interest.

    Returns boolean

    true if the plugin is activated, false otherwise.

  • List the IDs of the plugins registered with the application.

    Returns string[]

    A new array of the registered plugin IDs.

  • Register a plugin with the application.

    Parameters

    • plugin: IPlugin<Application<T>, any>

      The plugin to register.

      Notes

      An error will be thrown if a plugin with the same ID is already registered, or if the plugin has a circular dependency.

      If the plugin provides a service which has already been provided by another plugin, the new service will override the old service.

    Returns void

  • Register multiple plugins with the application.

    Parameters

    • plugins: IPlugin<Application<T>, any>[]

      The plugins to register.

      Notes

      This calls registerPlugin() for each of the given plugins.

    Returns void

  • Resolve an optional service of a given type.

    Type Parameters

    • U

    Parameters

    • token: Token<U>

      The token for the service type of interest.

    Returns Promise<null | U>

    A promise which resolves to an instance of the requested service, or null if it cannot be resolved.

    Notes

    Services are singletons. The same instance will be returned each time a given service token is resolved.

    If the plugin which provides the service has not been activated, resolving the service will automatically activate the plugin.

    User code will not typically call this method directly. Instead, the optional services for the user's plugins will be resolved automatically when the plugin is activated.

  • Resolve a required service of a given type.

    Type Parameters

    • U

    Parameters

    • token: Token<U>

      The token for the service type of interest.

    Returns Promise<U>

    A promise which resolves to an instance of the requested service, or rejects with an error if it cannot be resolved.

    Notes

    Services are singletons. The same instance will be returned each time a given service token is resolved.

    If the plugin which provides the service has not been activated, resolving the service will automatically activate the plugin.

    User code will not typically call this method directly. Instead, the required services for the user's plugins will be resolved automatically when the plugin is activated.

  • Start the application.

    Parameters

    Returns Promise<void>

    A promise which resolves when all bootstrapping work is complete and the shell is mounted to the DOM.

    Notes

    This should be called once by the application creator after all initial plugins have been registered.

    If a plugin fails to the load, the error will be logged and the other valid plugins will continue to be loaded.

    Bootstrapping the application consists of the following steps:

    1. Activate the startup plugins
    2. Wait for those plugins to activate
    3. Attach the shell widget to the DOM
    4. Add the application event listeners