Skip to content

Documentation / @ripl/core / ContextFactory

Type Alias: ContextFactory<TTarget, TOptions, TContext> ​

ContextFactory<TTarget, TOptions, TContext> = (target, options?) => TContext

Defined in: packages/core/src/context/types.ts:172

The factory shape every rendering backend exports as createContext: target-first, with a backend-specific target and options type. Backends legitimately diverge on TTarget; DOM backends (canvas, SVG, 3D) accept a string | HTMLElement mount target while non-DOM backends accept their own output adapter (e.g. the terminal backend's TerminalOutput). Synchronous backends return the constructed context directly and should conformance-check their factory against this type; asynchronous backends (e.g. WebGPU, which must await device acquisition) export the same target-first shape but return a Promise of the context instead.

Type Parameters ​

Type ParameterDescription
TTargetThe backend-specific target the context is created against.
TOptions extends ContextOptionsThe backend-specific options accepted by the factory.
TContext extends ContextThe concrete Context subclass the factory constructs.

Parameters ​

ParameterType
targetTTarget
options?TOptions

Returns ​

TContext