api.services
ServicesApi
Live objects one plugin holds out for others to use, found by name and watched for arriving.
A command is one thing to do; a service is a thing to hold — an account another
plugin signs in through, a connection, a catalogue. A plugin provides one live object
under a name and every other plugin reaches it by that name, whatever order they were
activated in: watch answers at once with what is there and again whenever the
provider arrives or goes.
The object's shape is the provider's to publish (a contract.d.ts in its repository,
taken as a dev dependency and imported with import type, which is erased before the
loader sees it); the editor never reads it. A name without a dot is namespaced under
the plugin ("account" → "scmjs-dev.account"); one with a dot is taken as it is.
Members
provide
provide<T extends object>(id: string, service: T, options?: ServiceOptions): Disposable;
Hold an object out under a name. Providing the same name again replaces it; the Disposable withdraws it.
get
get<T extends object>(id: string): T | null;
The object under a name, or null when no plugin provides it.
has
has(id: string): boolean;
watch
watch<T extends object>(id: string, listener: (service: T | null, info: ServiceInfo | null) => void): Disposable;
Called at once with the current object (or null) and again on every change of provider.
Types
Declarations only this group names.
ServiceOptionsinterface
interface ServiceOptions
version?: number | The provider's version of the contract, 1 by default; a consumer that needs a newer one checks |
|---|