Skip to content

Function: compose()

API / @xmachines/play-xstate / index / compose

Call Signature

function compose<TMachine>(Base): PlayerConstructor<TMachine>;

Defined in: packages/play-xstate/src/capabilities.ts:103

Builds an actor class from a base and a list of capabilities.

It applies each capability from left to right, so the LAST one is the outermost class, and the return type accumulates what each one adds: compose(PlayerActor, withRouting, withView) is Routable AND Viewable.

Use this form, and not the nested one. Each capability declares a FIXED return type, so withView(withRouting(PlayerActor)) builds the same class at run time and answers Viewable alone at the type level — a router bridge then refuses the actor with TS2739. The overloads below are what carries Routable through.

Type Parameters

Type Parameter
TMachine extends AnyStateMachine

Parameters

ParameterTypeDescription
BasePlayerConstructor<TMachine>The actor class to build on, normally PlayerActor.

Returns

PlayerConstructor<TMachine>

Example

import { definePlayer, PlayerActor, compose } from "@xmachines/play-xstate";
import { withRouting } from "@xmachines/play-xstate/routing";
import { withView } from "@xmachines/play-xstate/view";
const createPlayer = definePlayer({
machine,
actor: compose(PlayerActor, withRouting, withView),
});

Each overload takes the capabilities as separate arguments, c1 to c3, and it applies them from left to right.

Call Signature

function compose<TMachine, TC1>(Base, c1): PlayerConstructor<TMachine, TC1>;

Defined in: packages/play-xstate/src/capabilities.ts:106

Builds an actor class from a base and a list of capabilities.

It applies each capability from left to right, so the LAST one is the outermost class, and the return type accumulates what each one adds: compose(PlayerActor, withRouting, withView) is Routable AND Viewable.

Use this form, and not the nested one. Each capability declares a FIXED return type, so withView(withRouting(PlayerActor)) builds the same class at run time and answers Viewable alone at the type level — a router bridge then refuses the actor with TS2739. The overloads below are what carries Routable through.

Type Parameters

Type Parameter
TMachine extends AnyStateMachine
TC1 extends object

Parameters

ParameterTypeDescription
BasePlayerConstructor<TMachine>The actor class to build on, normally PlayerActor.
c1Capability<TMachine, TC1>-

Returns

PlayerConstructor<TMachine, TC1>

Example

import { definePlayer, PlayerActor, compose } from "@xmachines/play-xstate";
import { withRouting } from "@xmachines/play-xstate/routing";
import { withView } from "@xmachines/play-xstate/view";
const createPlayer = definePlayer({
machine,
actor: compose(PlayerActor, withRouting, withView),
});

Each overload takes the capabilities as separate arguments, c1 to c3, and it applies them from left to right.

Call Signature

function compose<TMachine, TC1, TC2>(Base, c1, c2): PlayerConstructor<TMachine, TC1 & TC2>;

Defined in: packages/play-xstate/src/capabilities.ts:110

Builds an actor class from a base and a list of capabilities.

It applies each capability from left to right, so the LAST one is the outermost class, and the return type accumulates what each one adds: compose(PlayerActor, withRouting, withView) is Routable AND Viewable.

Use this form, and not the nested one. Each capability declares a FIXED return type, so withView(withRouting(PlayerActor)) builds the same class at run time and answers Viewable alone at the type level — a router bridge then refuses the actor with TS2739. The overloads below are what carries Routable through.

Type Parameters

Type Parameter
TMachine extends AnyStateMachine
TC1 extends object
TC2 extends object

Parameters

ParameterTypeDescription
BasePlayerConstructor<TMachine>The actor class to build on, normally PlayerActor.
c1Capability<TMachine, TC1>-
c2Capability<TMachine, TC2>-

Returns

PlayerConstructor<TMachine, TC1 & TC2>

Example

import { definePlayer, PlayerActor, compose } from "@xmachines/play-xstate";
import { withRouting } from "@xmachines/play-xstate/routing";
import { withView } from "@xmachines/play-xstate/view";
const createPlayer = definePlayer({
machine,
actor: compose(PlayerActor, withRouting, withView),
});

Each overload takes the capabilities as separate arguments, c1 to c3, and it applies them from left to right.

Call Signature

function compose<TMachine, TC1, TC2, TC3>(
Base,
c1,
c2,
c3,
): PlayerConstructor<TMachine, TC1 & TC2 & TC3>;

Defined in: packages/play-xstate/src/capabilities.ts:115

Builds an actor class from a base and a list of capabilities.

It applies each capability from left to right, so the LAST one is the outermost class, and the return type accumulates what each one adds: compose(PlayerActor, withRouting, withView) is Routable AND Viewable.

Use this form, and not the nested one. Each capability declares a FIXED return type, so withView(withRouting(PlayerActor)) builds the same class at run time and answers Viewable alone at the type level — a router bridge then refuses the actor with TS2739. The overloads below are what carries Routable through.

Type Parameters

Type Parameter
TMachine extends AnyStateMachine
TC1 extends object
TC2 extends object
TC3 extends object

Parameters

ParameterTypeDescription
BasePlayerConstructor<TMachine>The actor class to build on, normally PlayerActor.
c1Capability<TMachine, TC1>-
c2Capability<TMachine, TC2>-
c3Capability<TMachine, TC3>-

Returns

PlayerConstructor<TMachine, TC1 & TC2 & TC3>

Example

import { definePlayer, PlayerActor, compose } from "@xmachines/play-xstate";
import { withRouting } from "@xmachines/play-xstate/routing";
import { withView } from "@xmachines/play-xstate/view";
const createPlayer = definePlayer({
machine,
actor: compose(PlayerActor, withRouting, withView),
});

Each overload takes the capabilities as separate arguments, c1 to c3, and it applies them from left to right.