with-routing
API / @xmachines/play-xstate / with-routing
The routing capability of an XState actor, as a mixin.
PlayerActor holds state and send, and nothing about a route. This module adds
currentRoute and initialRoute, which is what Routable of @xmachines/play-router
asks for and what every router bridge reads.
It is a SEPARATE entry point, @xmachines/play-xstate/routing, and the core imports it
never. @xmachines/play-router is an OPTIONAL peer of this package for the same reason:
an application that declares no route installs neither that package nor the route map
and the bridge that it carries.
Example
import { definePlayer, PlayerActor, compose } from "@xmachines/play-xstate";import { withRouting } from "@xmachines/play-xstate/routing";
const createPlayer = definePlayer({ machine, actor: compose(PlayerActor, withRouting) });const actor = createPlayer();actor.currentRoute.get(); // "/profile/alice"