@intisy/bayonet
    Preparing search index...

    Interface Services

    How a plugin reaches another plugin's API, and offers its own.

    A typed handle, never an import: the plugin answering is whichever one registered the id, so no plugin ever names another. This is what makes a plugin terminal, and it is the reason a host needs no import of anything it drives.

    interface Services {
        get<T>(type: ServiceType<T>): T | undefined;
        ids(): string[];
        register<T>(type: ServiceType<T>, implementation: T): () => void;
        want<T>(type: ServiceType<T>): Promise<T>;
        want<T>(type: ServiceType<T>, options: WantOptions): Promise<T>;
        watch<T>(
            type: ServiceType<T>,
            listener: (a: T, b: string) => void,
        ): () => void;
    }
    Index
    • What is registered under this id right now, or absent when nothing is.

      Type Parameters

      • T

        the service's API type

      Parameters

      Returns T | undefined

      the current registration, or null when none is registered

    • Every service id registered right now.

      Returns string[]

      the registered service ids

    • Offers an implementation under this id, until the returned function is called.

      Type Parameters

      • T

        the service's API type

      Parameters

      • type: ServiceType<T>

        the service key, from (String)

      • implementation: T

        this plugin's implementation of the service

      Returns () => void

      a function that withdraws the registration when called

    • Waits for the id to be registered, for a host default the implementation chooses.

      Type Parameters

      • T

        the service's API type

      Parameters

      Returns Promise<T>

      a stage that completes with the registration once one appears

    • Waits for the id to be registered, giving up after the stated time.

      Type Parameters

      • T

        the service's API type

      Parameters

      Returns Promise<T>

      a stage that completes with the registration, or fails once the wait times out

    • Reports every registration and removal of this id until the returned function is called. The listener is handed the service and either "register" or "unregister"; on the latter the service is absent.

      Type Parameters

      • T

        the service's API type

      Parameters

      • type: ServiceType<T>

        the service key, from (String)

      • listener: (a: T, b: string) => void

        called with the current registration (or absent) and the event kind

      Returns () => void

      a function that stops the watch when called

      Distinct from want, which answers once: a service can be replaced while a consumer is still holding the old one, and only a watcher sees that.