@xmachines/docs 1.0.0-beta.26 → 1.0.0-beta.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/@xmachines/play/classes/PlayError.md +4 -4
- package/api/@xmachines/play/type-aliases/PlayEvent.md +2 -2
- package/api/@xmachines/play-actor/classes/AbstractActor.md +3 -3
- package/api/@xmachines/play-actor/functions/typedSpec.md +1 -1
- package/api/@xmachines/play-actor/interfaces/PlaySpec.md +2 -2
- package/api/@xmachines/play-actor/interfaces/Routable.md +3 -3
- package/api/@xmachines/play-actor/interfaces/ViewMetadata.md +3 -3
- package/api/@xmachines/play-actor/interfaces/Viewable.md +2 -2
- package/api/@xmachines/play-dom/README.md +24 -8
- package/api/@xmachines/play-dom/classes/PlayRenderer.md +4 -4
- package/api/@xmachines/play-dom/functions/connectRenderer.md +1 -1
- package/api/@xmachines/play-dom/functions/defineRegistry.md +61 -0
- package/api/@xmachines/play-dom/functions/renderSpec.md +29 -12
- package/api/@xmachines/play-dom/interfaces/ComponentContext.md +62 -0
- package/api/@xmachines/play-dom/interfaces/ConnectRendererOptions.md +9 -9
- package/api/@xmachines/play-dom/interfaces/DefineRegistryOptions.md +25 -0
- package/api/@xmachines/play-dom/interfaces/DefineRegistryResult.md +18 -0
- package/api/@xmachines/play-dom/interfaces/DomRenderContext.md +13 -10
- package/api/@xmachines/play-dom/interfaces/EventHandle.md +29 -0
- package/api/@xmachines/play-dom/interfaces/PlayDomOptions.md +5 -5
- package/api/@xmachines/play-dom/type-aliases/ComponentFn.md +53 -0
- package/api/@xmachines/play-dom/type-aliases/ComponentRegistry.md +21 -0
- package/api/@xmachines/play-dom/type-aliases/DomComponentRenderer.md +16 -3
- package/api/@xmachines/play-dom/type-aliases/DomRegistry.md +5 -2
- package/api/@xmachines/play-dom-router/functions/connectRouter.md +1 -1
- package/api/@xmachines/play-dom-router/functions/createBrowserHistory.md +1 -1
- package/api/@xmachines/play-dom-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-dom-router/functions/createRouter.md +1 -1
- package/api/@xmachines/play-dom-router/interfaces/BrowserHistory.md +14 -14
- package/api/@xmachines/play-dom-router/interfaces/BrowserWindow.md +14 -14
- package/api/@xmachines/play-dom-router/interfaces/ConnectRouterOptions.md +4 -4
- package/api/@xmachines/play-dom-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-dom-router/interfaces/RouteMap.md +3 -3
- package/api/@xmachines/play-dom-router/interfaces/RouteMapLike.md +3 -3
- package/api/@xmachines/play-dom-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-dom-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-dom-router/interfaces/VanillaRouter.md +4 -4
- package/api/@xmachines/play-dom-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-dom-router-demo/README.md +46 -51
- package/api/@xmachines/play-react/classes/PlayErrorBoundary.md +5 -5
- package/api/@xmachines/play-react/functions/useActor.md +1 -1
- package/api/@xmachines/play-react/functions/useSignalEffect.md +1 -1
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryProps.md +4 -4
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryState.md +3 -3
- package/api/@xmachines/play-react/interfaces/PlayRendererProps.md +7 -7
- package/api/@xmachines/play-react/type-aliases/PlayActor.md +1 -1
- package/api/@xmachines/play-react/variables/PlayRenderer.md +1 -1
- package/api/@xmachines/play-react-router/classes/ReactRouterBridge.md +23 -23
- package/api/@xmachines/play-react-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-react-router/functions/PlayRouterProvider.md +1 -1
- package/api/@xmachines/play-react-router/functions/createRouteMapFromTree.md +1 -1
- package/api/@xmachines/play-react-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-react-router/interfaces/PlayRouterProviderProps.md +5 -5
- package/api/@xmachines/play-react-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-react-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-router/classes/BaseRouteMap.md +4 -4
- package/api/@xmachines/play-router/classes/RouterBridgeBase.md +23 -23
- package/api/@xmachines/play-router/functions/buildPlayRouteEvent.md +1 -1
- package/api/@xmachines/play-router/functions/buildRouteTree.md +1 -1
- package/api/@xmachines/play-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-router/functions/createRouteMapFromMachine.md +1 -1
- package/api/@xmachines/play-router/functions/createRouteMapFromTree.md +1 -1
- package/api/@xmachines/play-router/functions/detectDuplicateRoutes.md +1 -1
- package/api/@xmachines/play-router/functions/extractMachineRoutes.md +1 -1
- package/api/@xmachines/play-router/functions/extractQuery.md +1 -1
- package/api/@xmachines/play-router/functions/extractRouteParams.md +1 -1
- package/api/@xmachines/play-router/functions/findRouteById.md +1 -1
- package/api/@xmachines/play-router/functions/findRouteByPath.md +1 -1
- package/api/@xmachines/play-router/functions/getNavigableRoutes.md +1 -1
- package/api/@xmachines/play-router/functions/getRoutableRoutes.md +1 -1
- package/api/@xmachines/play-router/functions/getTransitionReachableRoutes.md +1 -1
- package/api/@xmachines/play-router/functions/isRouteReachable.md +1 -1
- package/api/@xmachines/play-router/functions/machineToGraph.md +1 -1
- package/api/@xmachines/play-router/functions/routeExists.md +1 -1
- package/api/@xmachines/play-router/functions/sanitizePathname.md +1 -1
- package/api/@xmachines/play-router/functions/validateRouteFormat.md +1 -1
- package/api/@xmachines/play-router/functions/validateStateExists.md +1 -1
- package/api/@xmachines/play-router/interfaces/BuildPlayRouteEventOptions.md +4 -4
- package/api/@xmachines/play-router/interfaces/LocationLike.md +3 -3
- package/api/@xmachines/play-router/interfaces/MachineEdgeData.md +3 -3
- package/api/@xmachines/play-router/interfaces/MachineNodeData.md +5 -5
- package/api/@xmachines/play-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-router/interfaces/RouteInfo.md +8 -8
- package/api/@xmachines/play-router/interfaces/RouteMap.md +4 -4
- package/api/@xmachines/play-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-router/interfaces/RouteMatch.md +3 -3
- package/api/@xmachines/play-router/interfaces/RouteNode.md +10 -10
- package/api/@xmachines/play-router/interfaces/RouteObject.md +2 -2
- package/api/@xmachines/play-router/interfaces/RouteTree.md +5 -5
- package/api/@xmachines/play-router/interfaces/RouteWatcherHandle.md +3 -3
- package/api/@xmachines/play-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-router/interfaces/WindowLike.md +3 -3
- package/api/@xmachines/play-router/type-aliases/MachineGraph.md +1 -1
- package/api/@xmachines/play-router/type-aliases/RouteMetadata.md +1 -1
- package/api/@xmachines/play-signals/functions/watchSignal.md +1 -1
- package/api/@xmachines/play-signals/interfaces/ComputedOptions.md +2 -2
- package/api/@xmachines/play-signals/interfaces/SignalComputed.md +2 -2
- package/api/@xmachines/play-signals/interfaces/SignalOptions.md +2 -2
- package/api/@xmachines/play-signals/interfaces/SignalState.md +3 -3
- package/api/@xmachines/play-signals/interfaces/SignalWatcher.md +4 -4
- package/api/@xmachines/play-signals/type-aliases/WatcherNotify.md +1 -1
- package/api/@xmachines/play-solid/functions/useActor.md +1 -1
- package/api/@xmachines/play-solid/interfaces/PlayRendererProps.md +7 -7
- package/api/@xmachines/play-solid/type-aliases/PlayActor.md +1 -1
- package/api/@xmachines/play-solid/variables/PlayRenderer.md +1 -1
- package/api/@xmachines/play-solid-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-solid-router/classes/SolidRouterBridge.md +24 -24
- package/api/@xmachines/play-solid-router/functions/PlayRouterProvider.md +1 -1
- package/api/@xmachines/play-solid-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-solid-router/interfaces/AbstractActor.md +3 -3
- package/api/@xmachines/play-solid-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-solid-router/interfaces/PlayRouterProviderProps.md +5 -5
- package/api/@xmachines/play-solid-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-solid-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-solid-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-solid-router/type-aliases/SolidRouterHooks.md +4 -4
- package/api/@xmachines/play-solid-router-demo/README.md +25 -28
- package/api/@xmachines/play-svelte/interfaces/PlayRendererProps.md +7 -7
- package/api/@xmachines/play-svelte-spa-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-svelte-spa-router/functions/connectRouter.md +1 -1
- package/api/@xmachines/play-svelte-spa-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-svelte-spa-router/interfaces/ConnectRouterOptions.md +4 -4
- package/api/@xmachines/play-svelte-spa-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-svelte-spa-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-svelte-spa-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-svelte-spa-router/interfaces/WindowLike.md +3 -3
- package/api/@xmachines/play-svelte-spa-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-svelte-spa-router-demo/README.md +119 -12
- package/api/@xmachines/play-sveltekit-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-sveltekit-router/functions/connectRouter.md +1 -1
- package/api/@xmachines/play-sveltekit-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-sveltekit-router/interfaces/ConnectRouterOptions.md +4 -4
- package/api/@xmachines/play-sveltekit-router/interfaces/LocationLike.md +3 -3
- package/api/@xmachines/play-sveltekit-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-sveltekit-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-sveltekit-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-sveltekit-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-sveltekit-router-demo/README.md +120 -12
- package/api/@xmachines/play-tanstack-react-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-tanstack-react-router/classes/TanStackReactRouterBridge.md +23 -23
- package/api/@xmachines/play-tanstack-react-router/functions/PlayRouterProvider.md +1 -1
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMapFromTree.md +1 -1
- package/api/@xmachines/play-tanstack-react-router/functions/extractMachineRoutes.md +1 -1
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouterProviderProps.md +5 -5
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteNavigateEvent.md +3 -3
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterInstance.md +1 -1
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterLike.md +17 -3
- package/api/@xmachines/play-tanstack-react-router-demo/README.md +23 -29
- package/api/@xmachines/play-tanstack-solid-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-tanstack-solid-router/classes/SolidRouterBridge.md +24 -24
- package/api/@xmachines/play-tanstack-solid-router/functions/PlayRouterProvider.md +1 -1
- package/api/@xmachines/play-tanstack-solid-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouterProviderProps.md +5 -5
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterInstance.md +1 -1
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterLike.md +3 -3
- package/api/@xmachines/play-tanstack-solid-router-demo/README.md +25 -26
- package/api/@xmachines/play-vue/functions/defineRegistry.md +1 -1
- package/api/@xmachines/play-vue/functions/useActor.md +1 -1
- package/api/@xmachines/play-vue/interfaces/PlayRendererProps.md +5 -5
- package/api/@xmachines/play-vue/type-aliases/ComponentEntry.md +1 -1
- package/api/@xmachines/play-vue/type-aliases/ComponentsMap.md +1 -1
- package/api/@xmachines/play-vue/type-aliases/DefineRegistryOptions.md +4 -3
- package/api/@xmachines/play-vue/type-aliases/PlayActor.md +1 -1
- package/api/@xmachines/play-vue/variables/PlayRenderer.md +1 -1
- package/api/@xmachines/play-vue-router/classes/RouteMap.md +4 -4
- package/api/@xmachines/play-vue-router/classes/VueBaseRouteMap.md +4 -4
- package/api/@xmachines/play-vue-router/classes/VueRouterBridge.md +24 -24
- package/api/@xmachines/play-vue-router/functions/createRouteMap.md +1 -1
- package/api/@xmachines/play-vue-router/interfaces/PlayRouteEvent.md +6 -6
- package/api/@xmachines/play-vue-router/interfaces/RouteMapping.md +3 -3
- package/api/@xmachines/play-vue-router/interfaces/RouterBridge.md +3 -3
- package/api/@xmachines/play-vue-router/type-aliases/RoutableActor.md +1 -1
- package/api/@xmachines/play-vue-router/variables/PlayRouterProvider.md +1 -1
- package/api/@xmachines/play-vue-router-demo/README.md +47 -40
- package/api/@xmachines/play-xstate/classes/PlayerActor.md +11 -11
- package/api/@xmachines/play-xstate/functions/buildRouteUrl.md +1 -1
- package/api/@xmachines/play-xstate/functions/composeGuards.md +1 -1
- package/api/@xmachines/play-xstate/functions/composeGuardsOr.md +1 -1
- package/api/@xmachines/play-xstate/functions/contextFieldMatches.md +1 -1
- package/api/@xmachines/play-xstate/functions/definePlayer.md +1 -1
- package/api/@xmachines/play-xstate/functions/deriveRoute.md +1 -1
- package/api/@xmachines/play-xstate/functions/eventMatches.md +1 -1
- package/api/@xmachines/play-xstate/functions/formatPlayRouteTransitions.md +1 -1
- package/api/@xmachines/play-xstate/functions/hasContext.md +1 -1
- package/api/@xmachines/play-xstate/functions/isAbsoluteRoute.md +1 -1
- package/api/@xmachines/play-xstate/functions/negateGuard.md +1 -1
- package/api/@xmachines/play-xstate/interfaces/PlayerConfig.md +3 -3
- package/api/@xmachines/play-xstate/interfaces/PlayerFactoryResumeOptions.md +2 -2
- package/api/@xmachines/play-xstate/interfaces/PlayerOptions.md +6 -6
- package/api/@xmachines/play-xstate/interfaces/RouteContext.md +5 -5
- package/api/@xmachines/play-xstate/type-aliases/ComposedGuard.md +1 -1
- package/api/@xmachines/play-xstate/type-aliases/Guard.md +1 -1
- package/api/@xmachines/play-xstate/type-aliases/GuardArray.md +1 -1
- package/api/@xmachines/play-xstate/type-aliases/PlayerFactory.md +1 -1
- package/api/@xmachines/play-xstate/type-aliases/RouteMachineConfig.md +4 -4
- package/api/@xmachines/play-xstate/type-aliases/RouteStateNode.md +4 -4
- package/api/@xmachines/shared/functions/defineXmVitestConfig.md +3 -7
- package/api/@xmachines/shared/functions/xmAliases.md +1 -1
- package/examples/README.md +48 -35
- package/examples/basic-state-machine.md +75 -31
- package/examples/form-validation.md +199 -127
- package/examples/multi-router-integration.md +312 -230
- package/examples/routing-patterns.md +243 -189
- package/examples/traffic-light.md +114 -65
- package/guides/README.md +29 -15
- package/guides/getting-started.md +224 -144
- package/guides/installation.md +153 -213
- package/package.json +2 -2
|
@@ -1,99 +1,148 @@
|
|
|
1
|
+
<!-- generated-by: gsd-doc-writer -->
|
|
2
|
+
|
|
1
3
|
# Traffic Light State Machine
|
|
2
4
|
|
|
3
|
-
Multi-state machine with
|
|
5
|
+
Multi-state machine with `meta.route` on every state, demonstrating cyclic transitions and `formatPlayRouteTransitions`.
|
|
4
6
|
|
|
5
7
|
## Use Case
|
|
6
8
|
|
|
7
|
-
This example models a traffic light with a red → green → yellow → red cycle.
|
|
9
|
+
This example models a traffic light with a red → green → yellow → red cycle. Because traffic lights map naturally to URLs (each light colour is a distinct page in a web app), it is a good vehicle for showing how `meta.route` and `formatPlayRouteTransitions` work together.
|
|
10
|
+
|
|
11
|
+
Applicable patterns:
|
|
8
12
|
|
|
9
13
|
- Traffic light controllers
|
|
10
14
|
- Multi-step workflows with repeating cycles
|
|
11
|
-
-
|
|
12
|
-
-
|
|
15
|
+
- Tab or wizard navigation where each step has a URL
|
|
16
|
+
- Game state loops with distinct URL states
|
|
13
17
|
|
|
14
18
|
## Complete Code
|
|
15
19
|
|
|
16
20
|
```typescript
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const trafficMachine = createMachine<TrafficState, TrafficEvent>({
|
|
27
|
-
id: "traffic",
|
|
28
|
-
initial: "red",
|
|
29
|
-
states: {
|
|
30
|
-
red: {
|
|
31
|
-
on: {
|
|
32
|
-
TIMER: "green",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
green: {
|
|
36
|
-
on: {
|
|
37
|
-
TIMER: "yellow",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
yellow: {
|
|
41
|
-
on: {
|
|
42
|
-
TIMER: "red",
|
|
43
|
-
},
|
|
21
|
+
import { setup } from "xstate";
|
|
22
|
+
import { definePlayer, formatPlayRouteTransitions } from "@xmachines/play-xstate";
|
|
23
|
+
|
|
24
|
+
// 1. Typed setup
|
|
25
|
+
const trafficSetup = setup({
|
|
26
|
+
types: {
|
|
27
|
+
context: {} as {
|
|
28
|
+
params: Record<string, string>;
|
|
29
|
+
query: Record<string, string>;
|
|
44
30
|
},
|
|
31
|
+
events: {} as
|
|
32
|
+
| { type: "timer" }
|
|
33
|
+
| {
|
|
34
|
+
type: "play.route";
|
|
35
|
+
to: string;
|
|
36
|
+
params?: Record<string, string>;
|
|
37
|
+
query?: Record<string, string>;
|
|
38
|
+
},
|
|
39
|
+
input: {} as undefined,
|
|
45
40
|
},
|
|
46
41
|
});
|
|
47
42
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
// 2. Machine with meta.route on every state
|
|
44
|
+
// formatPlayRouteTransitions() reads each state's id + meta.route and
|
|
45
|
+
// auto-generates the root-level play.route event handlers.
|
|
46
|
+
const trafficMachine = trafficSetup.createMachine(
|
|
47
|
+
formatPlayRouteTransitions({
|
|
48
|
+
id: "traffic",
|
|
49
|
+
initial: "red",
|
|
50
|
+
context: {
|
|
51
|
+
params: {},
|
|
52
|
+
query: {},
|
|
53
|
+
},
|
|
54
|
+
states: {
|
|
55
|
+
red: {
|
|
56
|
+
id: "red",
|
|
57
|
+
meta: { route: "/red" },
|
|
58
|
+
on: { timer: "green" },
|
|
59
|
+
},
|
|
60
|
+
green: {
|
|
61
|
+
id: "green",
|
|
62
|
+
meta: { route: "/green" },
|
|
63
|
+
on: { timer: "yellow" },
|
|
64
|
+
},
|
|
65
|
+
yellow: {
|
|
66
|
+
id: "yellow",
|
|
67
|
+
meta: { route: "/yellow" },
|
|
68
|
+
on: { timer: "red" },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
51
73
|
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
state = trafficMachine.transition(state, { type: "TIMER" });
|
|
55
|
-
console.log(`Light changed to: ${state}`);
|
|
56
|
-
}, 3000); // Change every 3 seconds
|
|
57
|
-
```
|
|
74
|
+
// 3. Player factory
|
|
75
|
+
const createPlayer = definePlayer({ machine: trafficMachine });
|
|
58
76
|
|
|
59
|
-
|
|
77
|
+
// 4. Create and start actor
|
|
78
|
+
const actor = createPlayer();
|
|
79
|
+
actor.start();
|
|
60
80
|
|
|
61
|
-
|
|
81
|
+
// 5. Read current route via signal
|
|
82
|
+
console.log(actor.currentRoute.get()); // "/red"
|
|
62
83
|
|
|
63
|
-
|
|
84
|
+
// 6. Advance with domain events
|
|
85
|
+
actor.send({ type: "timer" });
|
|
86
|
+
console.log(actor.currentRoute.get()); // "/green"
|
|
64
87
|
|
|
65
|
-
|
|
88
|
+
actor.send({ type: "timer" });
|
|
89
|
+
console.log(actor.currentRoute.get()); // "/yellow"
|
|
66
90
|
|
|
67
|
-
|
|
91
|
+
actor.send({ type: "timer" });
|
|
92
|
+
console.log(actor.currentRoute.get()); // "/red"
|
|
68
93
|
|
|
69
|
-
|
|
94
|
+
// 7. Or navigate directly via play.route events (generated by formatPlayRouteTransitions)
|
|
95
|
+
actor.send({ type: "play.route", to: "#green" });
|
|
96
|
+
console.log(actor.currentRoute.get()); // "/green"
|
|
70
97
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- **Deterministic**: Same sequence of events always produces the same sequence of states
|
|
98
|
+
// 8. Cleanup
|
|
99
|
+
actor.stop();
|
|
100
|
+
```
|
|
75
101
|
|
|
76
|
-
##
|
|
102
|
+
## How `formatPlayRouteTransitions` Works
|
|
77
103
|
|
|
78
|
-
**
|
|
104
|
+
`formatPlayRouteTransitions` crawls every state that has **both** an `id` and a `meta.route`, then generates root-level `play.route` event handlers of the form:
|
|
79
105
|
|
|
80
106
|
```typescript
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
scheduleNext();
|
|
89
|
-
}, timings[state]);
|
|
107
|
+
// Auto-generated by formatPlayRouteTransitions — you don't write this manually:
|
|
108
|
+
on: {
|
|
109
|
+
"play.route": [
|
|
110
|
+
{ target: ".red", guard: ({ event }) => event.to === "#red", reenter: true, actions: assign({ params, query }) },
|
|
111
|
+
{ target: ".green", guard: ({ event }) => event.to === "#green", reenter: true, actions: assign({ params, query }) },
|
|
112
|
+
{ target: ".yellow", guard: ({ event }) => event.to === "#yellow", reenter: true, actions: assign({ params, query }) },
|
|
113
|
+
],
|
|
90
114
|
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Requirements:**
|
|
118
|
+
|
|
119
|
+
- Every routable state must have both `id` (the `#id` navigation target) and `meta.route` (the URL template).
|
|
120
|
+
- The machine's context must include `params` and `query` fields (both `Record<string, string>`), because `formatPlayRouteTransitions` assigns them on every `play.route` transition.
|
|
91
121
|
|
|
92
|
-
|
|
122
|
+
## `actor.currentRoute` Signal
|
|
123
|
+
|
|
124
|
+
`actor.currentRoute` is a `Signal.Computed<string | null>` derived from the active state's `meta.route` template and `context.params`. Route signals let router bridges observe URL changes reactively without polling.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { watchSignal } from "@xmachines/play-signals";
|
|
128
|
+
|
|
129
|
+
const unwatch = watchSignal(actor.currentRoute, () => {
|
|
130
|
+
console.log("URL changed to:", actor.currentRoute.get());
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// later...
|
|
134
|
+
unwatch();
|
|
93
135
|
```
|
|
94
136
|
|
|
137
|
+
## Key Concepts
|
|
138
|
+
|
|
139
|
+
- **`meta.route`**: Marks a state as routable. The value is a URL template (e.g. `"/profile/:username"`).
|
|
140
|
+
- **`formatPlayRouteTransitions`**: Utility that auto-generates `play.route` handlers from `id` + `meta.route` pairs. Wrap your machine config before passing to `createMachine`.
|
|
141
|
+
- **`actor.currentRoute`**: TC39 `Signal.Computed` containing the resolved URL for the active state.
|
|
142
|
+
- **`play.route` events**: Navigation events with a `to: "#stateId"` target. Use `to: "#red"` (state ID), not `to: "/red"` (URL path).
|
|
143
|
+
|
|
95
144
|
## Next Steps
|
|
96
145
|
|
|
97
|
-
- **[Form Validation Example](form-validation.md)**
|
|
98
|
-
- **[
|
|
99
|
-
- **[
|
|
146
|
+
- **[Form Validation Example](form-validation.md)** — Context mutations with `setup.assign` and guards
|
|
147
|
+
- **[Routing Patterns](routing-patterns.md)** — Parameter routes, relative routes, and `always` auth guards
|
|
148
|
+
- **[Play RFC](../rfc/play.md)** — Complete architectural specification
|
package/guides/README.md
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
|
+
<!-- generated-by: gsd-doc-writer -->
|
|
2
|
+
|
|
1
3
|
# XMachines Guides
|
|
2
4
|
|
|
3
|
-
Entry points for current XMachines Play architecture
|
|
5
|
+
Entry points for the current XMachines Play architecture.
|
|
4
6
|
|
|
5
7
|
## Start Here
|
|
6
8
|
|
|
7
|
-
- [
|
|
9
|
+
- **[Installation](installation.md)** — Core packages, framework-specific additions, TypeScript config, ESM setup
|
|
10
|
+
- **[Getting Started](getting-started.md)** — `setup().createMachine()` → `definePlayer()` → `actor.start()` → TC39 Signals
|
|
11
|
+
|
|
12
|
+
## Examples
|
|
13
|
+
|
|
14
|
+
- **[Examples Index](../examples/README.md)** — Conceptual patterns and complete runnable demo applications
|
|
8
15
|
|
|
9
16
|
## Router Adapter Guides
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
Framework-specific adapter documentation:
|
|
19
|
+
|
|
20
|
+
- **[@xmachines/play-router](../api/@xmachines/play-router/README.md)** — Route extraction, route maps, and `RouterBridgeBase`
|
|
21
|
+
- **[@xmachines/play-tanstack-react-router](../api/@xmachines/play-tanstack-react-router/README.md)** — TanStack React adapter (`PlayRouterProvider`, `createRouteMapFromTree`)
|
|
22
|
+
- **[@xmachines/play-react-router](../api/@xmachines/play-react-router/README.md)** — React Router v7 data-router adapter
|
|
23
|
+
- **[@xmachines/play-tanstack-solid-router](../api/@xmachines/play-tanstack-solid-router/README.md)** — TanStack Solid adapter
|
|
24
|
+
- **[@xmachines/play-solid-router](../api/@xmachines/play-solid-router/README.md)** — SolidJS Router adapter
|
|
25
|
+
- **[@xmachines/play-vue-router](../api/@xmachines/play-vue-router/README.md)** — Vue Router adapter
|
|
26
|
+
- **[@xmachines/play-dom-router](../api/@xmachines/play-dom-router/README.md)** — Vanilla DOM: `connectRouter`, `createBrowserHistory`, `createRouter`
|
|
27
|
+
- **[@xmachines/play-sveltekit-router](../api/@xmachines/play-sveltekit-router/README.md)** — SvelteKit adapter
|
|
28
|
+
- **[@xmachines/play-svelte-spa-router](../api/@xmachines/play-svelte-spa-router/README.md)** — Svelte SPA Router (hash-based) adapter
|
|
12
29
|
|
|
13
|
-
|
|
14
|
-
- [@xmachines/play-tanstack-react-router](../api/@xmachines/play-tanstack-react-router/README.md) - TanStack React adapter
|
|
15
|
-
- [@xmachines/play-react-router](../api/@xmachines/play-react-router/README.md) - `react-router` v7 data-router adapter
|
|
16
|
-
- [@xmachines/play-tanstack-solid-router](../api/@xmachines/play-tanstack-solid-router/README.md) - TanStack Solid adapter
|
|
17
|
-
- [@xmachines/play-solid-router](../api/@xmachines/play-solid-router/README.md) - SolidJS Router adapter
|
|
18
|
-
- [@xmachines/play-vue-router](../api/@xmachines/play-vue-router/README.md) - Vue Router adapter
|
|
30
|
+
## Renderer Guides
|
|
19
31
|
|
|
20
|
-
|
|
32
|
+
View layer documentation by framework:
|
|
21
33
|
|
|
22
|
-
- [@xmachines/play-xstate](../api/@xmachines/play-xstate/README.md)
|
|
23
|
-
- [@xmachines/play-react](../api/@xmachines/play-react/README.md)
|
|
24
|
-
- [@xmachines/play-vue](../api/@xmachines/play-vue/README.md)
|
|
25
|
-
- [@xmachines/play-solid](../api/@xmachines/play-solid/README.md)
|
|
34
|
+
- **[@xmachines/play-xstate](../api/@xmachines/play-xstate/README.md)** — `definePlayer`, `formatPlayRouteTransitions`, `PlayerActor`
|
|
35
|
+
- **[@xmachines/play-react](../api/@xmachines/play-react/README.md)** — React rendering from actor-driven view state (`PlayRenderer`, `defineRegistry`)
|
|
36
|
+
- **[@xmachines/play-vue](../api/@xmachines/play-vue/README.md)** — Vue rendering from actor-driven view state
|
|
37
|
+
- **[@xmachines/play-solid](../api/@xmachines/play-solid/README.md)** — SolidJS rendering from actor-driven view state
|
|
38
|
+
- **[@xmachines/play-svelte](../api/@xmachines/play-svelte/README.md)** — Svelte 5 rendering from actor-driven view state
|
|
39
|
+
- **[@xmachines/play-dom](../api/@xmachines/play-dom/README.md)** — Vanilla DOM rendering (`connectRenderer`, `defineRegistry`)
|
|
26
40
|
|
|
27
41
|
## API Reference
|
|
28
42
|
|
|
29
|
-
- [API Reference](../api/README.md)
|
|
43
|
+
- **[API Reference](../api/README.md)** — Generated TypeDoc API docs for all public packages
|