API reference > @kontsedal/olas-core > defineController
defineController() function
Create a controller definition. The factory is stored on the returned object and invoked during createRoot / ctx.child to build instances.
Props defaults to void so a factory written as (ctx) => ... is typed as ControllerDef<void, Api> — the form createRoot requires.
Signature:
typescript
export declare function defineController<Props = void, Api = unknown>(factory: (ctx: Ctx, props: Props) => Api, options?: DefineControllerOptions): ControllerDef<Props, Api>;Parameters
Parameter | Type | Description |
|---|---|---|
factory | (ctx: Ctx, props: Props) => Api | |
options | (Optional) |
Returns:
ControllerDef<Props, Api>
Example
ts
export const counter = defineController(
(ctx) => {
const count = signal(0)
return { count, increment: () => count.update((n) => n + 1) }
},
{ name: 'counter' },
)