Skip to content

API reference > @kontsedal/olas-core > Ctx

Ctx type ​

ctx is the lifecycle-bound surface every controller factory receives. Every primitive constructed through ctx is owned by the controller and disposed when the controller disposes. The primitives are free functions that take ctx first (createField, createQuery, createMutation and the rest); ctx itself carries the tree and the lifetime.

Signature:

typescript
type Ctx<TDeps = AmbientDeps> = {
  emitter<T = void>(): Emitter<T>;
  child<Props, Api>(def: ControllerDef<Props, Api>, props: Props, options?: {
    deps?: Partial<TDeps>;
  }): Api;
  attach<Props, Api>(def: ControllerDef<Props, Api>, props: Props, options?: {
    deps?: Partial<TDeps>;
  }): {
    api: Api;
    dispose: () => void;
    suspend: () => void;
    resume: () => void;
  };
  collection<Item, K, Props, Api>(options: CollectionHomogeneousOptions<Item, K, Props, Api, TDeps>): Collection<K, Api>;
  collection<Item, K, R extends CollectionFactoryResult>(options: CollectionFactoryOptions<Item, K, R, TDeps>): Collection<K, CollectionFactoryApi<R>>;
  lazyChild<Props, Api>(loader: () => Promise<ControllerDef<Props, Api>>, props: Props, options?: {
    deps?: Partial<TDeps>;
  }): LazyChild<Api>;
  effect(fn: () => void | (() => void)): void;
  debug(values: Record<string, unknown>): void;
  on<T>(emitter: Emitter<T>, handler: (value: T) => void): void;
  provide<T>(scope: Scope<T>, value: T): void;
  inject<T>(scope: Scope<T>): T;
  onDispose(fn: () => void): void;
  onSuspend(fn: () => void): void;
  onResume(fn: () => void): void;
  readonly deps: TDeps;
};

References: AmbientDeps, Emitter, ControllerDef, CollectionHomogeneousOptions, Collection, CollectionFactoryResult, CollectionFactoryOptions, CollectionFactoryApi, LazyChild, Scope

Released under the MIT License.