Skip to content

createSetup

createSetup<T>(…setups: SetupFunc<T>[]): SetupFunc<T>

Defined in: ext/setup.ts:62

Composes multiple setup functions into a single setup function.

Usage:

const extensionSetup = createSetup(...extensions);
extensionSetup(machine1); // applies all extensions to machine1

Use cases:

  • Creating a reusable setup routine for multiple targets
  • Applying a set of extensions/setups to different machines/components
Type Parameter
T
ParameterTypeDescription
setupsSetupFunc<T>[]Setup functions to compose

SetupFunc<T>

A setup function that applies all setups to a target and returns a disposer

const setupA = (target: any) => () => console.log('A cleanup');
const setupB = (target: any) => () => console.log('B cleanup');
const extensionSetup = createSetup(setupA, setupB);
const dispose = extensionSetup({});
dispose(); // Logs 'B cleanup' then 'A cleanup'

This function is useful for creating a composite setup that can be applied to a target, allowing for modular and reusable setup logic. It allows multiple setups to be combined into one, making it easier to manage complex initialization logic in applications. It is particularly useful in scenarios where multiple setups need to be applied to a single target, such as in state machines, event handlers, or other components that require setup and teardown logic

export const createSetup: <T>(...setups: SetupFunc<T>[]) => SetupFunc<T> =
(...setups) =>
(target) =>
createDisposer(setups.map((fn) => fn(target)));