Skip to content

Context

/** Symbol key under which a disposer exposes its {@link EffectMeta} diagnostics tree. */
static readonly effect: unique symbol

Symbol key under which a disposer exposes its EffectMeta diagnostics tree.

Source

/** Symbol key for a context's listener filter, consulted on every event dispatch. */
static readonly filter: unique symbol

Symbol key for a context’s listener filter, consulted on every event dispatch.

Source

/** Symbol key of the isolation map (see the `Context[symbols.isolate]` property). */
static readonly isolate: unique symbol

Symbol key of the isolation map (see the Context[symbols.isolate] property).

Source

/** Symbol key of the intercept map (see the `Context[symbols.intercept]` property). */
static readonly intercept: unique symbol

Symbol key of the intercept map (see the Context[symbols.intercept] property).

Source

/**
* Returns true for Cordis context proxies and context prototypes.
*
* Works across realms and across multiple copies of cordis, because the
* brand is keyed by a global symbol rather than by `instanceof`.
*
* @param value — the value to test.
* @returns `true` if `value` is a Cordis context, narrowing its type.
*/
static is(value: any): value is Context

Returns true for Cordis context proxies and context prototypes.

Works across realms and across multiple copies of cordis, because the brand is keyed by a global symbol rather than by instanceof.

  • value — the value to test.

Returns true if value is a Cordis context, narrowing its type.

Source

/**
* Read a service from the store without the inject requirement.
*
* @param name — the service name.
* @param strict — when `true` (default), only return implementations
* whose providing fiber is currently active.
* @returns the service value, or `undefined` when not (yet) provided.
*/
get<K extends string & keyof this>(name: K, strict?: boolean): undefined | this[K]
get(name: string, strict?: boolean): any

Read a service from the store without the inject requirement.

  • name — the service name.
  • strict — when true (default), only return implementations whose providing fiber is currently active.

Returns the service value, or undefined when not (yet) provided.

Source

/**
* Overwrite a provided service's value.
*
* Only the fiber that provided the service may set it; setting an
* unprovided name throws.
*
* @param name — the service name.
* @param value — the new service value.
*/
set<K extends string & keyof this>(name: K, value: undefined | this[K]): void
set(name: string, value: any): void

Overwrite a provided service’s value.

Only the fiber that provided the service may set it; setting an unprovided name throws.

  • name — the service name.
  • value — the new service value.

Source

/**
* Register a service implementation owned by the current fiber.
*
* The service becomes visible to dependents in the same isolation scope
* once the fiber is active; it is unregistered (waking dependents) when
* the returned disposer runs or the fiber unloads. Throws if the name is
* already provided in this scope or declared as an accessor.
*
* @param name — the service name.
* @param value — the service value.
* @returns a disposer that unregisters the service.
*/
provide<K extends string & keyof this>(name: K, value: undefined | this[K]): () => void
provide(name: string, value?: any): () => void

Register a service implementation owned by the current fiber.

The service becomes visible to dependents in the same isolation scope once the fiber is active; it is unregistered (waking dependents) when the returned disposer runs or the fiber unloads. Throws if the name is already provided in this scope or declared as an accessor.

  • name — the service name.
  • value — the service value.

Returns a disposer that unregisters the service.

Source

/**
* Define a computed context property backed by get/set hooks.
*
* The accessor is removed when the current fiber unloads. Throws if the
* name is already declared.
*
* @param name — the context property name.
* @param options — the `get` hook and optional `set` hook.
*/
accessor(name: string, options: Omit<Property.Accessor, 'type'>): void

Define a computed context property backed by get/set hooks.

The accessor is removed when the current fiber unloads. Throws if the name is already declared.

  • name — the context property name.
  • options — the get hook and optional set hook.

Source

/**
* Expose selected members of a service directly on `ctx`.
*
* Each mixed-in key becomes an accessor that forwards to the service
* (binding methods to it), so e.g. `ctx.on` forwards to `ctx.events.on`.
* Mixins are removed when the current fiber unloads.
*
* @param name — the context property holding the source service.
* @param mixins — keys to forward, or a source-key → ctx-key map.
*/
mixin<K extends string & keyof this>(name: K, mixins: (keyof this & keyof this[K])[] | Dict<string>): void
mixin<T extends {}>(source: T, mixins: (keyof this & keyof T)[] | Dict<string>): void

Expose selected members of a service directly on ctx.

Each mixed-in key becomes an accessor that forwards to the service (binding methods to it), so e.g. ctx.on forwards to ctx.events.on. Mixins are removed when the current fiber unloads.

  • name — the context property holding the source service.
  • mixins — keys to forward, or a source-key → ctx-key map.

Source