createSetup
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 Parameters
Section titled “Type Parameters”Type Parameter |
---|
T |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
…setups | SetupFunc <T >[] | Setup functions to compose |
Returns
Section titled “Returns”SetupFunc
<T
>
A setup function that applies all setups to a target and returns a disposer
Example
Section titled “Example”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'
Source
Section titled “Source”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)));