x4js - v2.2.49
    Preparing search index...

    Class Application<E>

    The main application class, acting as a singleton. It manages the main view, environment variables, keyboard navigation, and provides utilities for local storage and WebSocket communication.

    Assertions ensure only one instance of Application can exist.

    Type Parameters

    Hierarchy (View Summary)

    Index
    process: Process = ...

    Provides access to process-related information, such as touch capabilities.

    • Clears all timeouts and intervals currently managed by this instance. This stops all scheduled callbacks and removes their references.

      Returns void

      setTimeout

    • Dispatches an event with a given name and payload to all registered listeners. If no listeners are registered for the event name, or if no EventSource has been initialized, this method does nothing.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to fire.

      • ev: E[K]

        The payload (event object) to pass to the listeners.

      Returns void

      • on
      • off
    • Moves focus to the next or previous focusable element within the application. Handles Tab and Shift+Tab key presses.

      Parameters

      • next: boolean

        If true, focus moves to the next element; if false, to the previous.

      Returns boolean

      true if focus was successfully moved, false otherwise.

    • Retrieves an environment variable from the application's environment map.

      Type Parameters

      • T = any

      Parameters

      • name: string

        The name of the environment variable.

      • Optionaldef_value: T

        An optional default value to return if the variable is not found.

      Returns T

      The value of the environment variable, or def_value if not found.

    • Retrieves a value from the browser's local storage.

      Parameters

      • name: string

        The key of the value to retrieve.

      Returns string

      The stored value as a string, or null if not found.

    • Retrieves and parses a JSON value from the browser's local storage.

      Parameters

      • name: string

        The key of the JSON value to retrieve.

      Returns any

      The parsed JSON object, or undefined if not found or parsing fails.

    • Removes a previously registered event listener. If the listener was not found or no events were registered, this method does nothing.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event from which to remove the listener.

      • listener: (ev: E[K]) => void

        The specific listener function to remove.

      Returns void

      • on
      • fire
    • Registers an event listener for a specific event name. The listener will be invoked when an event with the given name is fired. Returns an object with an off() method, which can be used to conveniently remove this specific listener.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to listen for.

      • listener: (ev: E[K]) => void

        The callback function to execute when the event is fired.

      Returns { off: () => void }

      An object containing an off() method to unsubscribe the listener.

      fire attach to an event

    • Sets an environment variable in the application's environment map.

      Type Parameters

      • T = any

      Parameters

      • name: string

        The name of the environment variable.

      • value: T

        The value to store for the environment variable.

      Returns void

    • Sets an interval that repeatedly executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.

      Parameters

      • name: string

        A unique string identifier for this timeout.

      • ms: number

        The delay in milliseconds before the callback is executed.

      • callback: () => void

        The function to execute after the delay.

      Returns void

    • Sets the main view component for the application. This component will be mounted to the DOM.

      Parameters

      • view: Component

        The component to set as the main view.

      Returns void

    • Stores a string or number value in the browser's local storage. The value will be converted to a string before storage.

      Parameters

      • name: string

        The key under which to store the value.

      • value: string | number

        The value to store.

      Returns void

    • Stores an object as a JSON string in the browser's local storage.

      Parameters

      • name: string

        The key under which to store the JSON value.

      • value: any

        The object to serialize and store.

      Returns void

    • Sets a timeout that executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.

      Parameters

      • name: string

        A unique string identifier for this timeout.

      • ms: number

        The delay in milliseconds before the callback is executed.

      • callback: () => void

        The function to execute after the delay.

      Returns void

    • Sets up WebSocket messaging for the application. All 'global' messages fired via the application will be sent over the WebSocket, and messages received from the WebSocket will be re-fired as 'global' messages.

      Parameters

      • Optionalpath: string

        Optional WebSocket path. If not provided, it defaults to ws://hostname:port/ws.

      • OptionallooseCallback: () => void

        A callback function to be executed when the WebSocket connection is closed unexpectedly.

      Returns void