@xmachines/docs 1.0.0-beta.10
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/LICENSE +21 -0
- package/README.md +15 -0
- package/api/@xmachines/play/README.md +130 -0
- package/api/@xmachines/play/type-aliases/PlayEvent.md +81 -0
- package/api/@xmachines/play-actor/README.md +247 -0
- package/api/@xmachines/play-actor/classes/AbstractActor.md +520 -0
- package/api/@xmachines/play-actor/interfaces/Routable.md +29 -0
- package/api/@xmachines/play-actor/interfaces/ViewMetadata.md +17 -0
- package/api/@xmachines/play-actor/interfaces/Viewable.md +12 -0
- package/api/@xmachines/play-catalog/README.md +331 -0
- package/api/@xmachines/play-catalog/functions/defineCatalog.md +98 -0
- package/api/@xmachines/play-catalog/functions/defineComponents.md +134 -0
- package/api/@xmachines/play-catalog/type-aliases/Catalog.md +48 -0
- package/api/@xmachines/play-catalog/type-aliases/ComponentsFor.md +20 -0
- package/api/@xmachines/play-catalog/type-aliases/InferComponentProps.md +65 -0
- package/api/@xmachines/play-catalog/type-aliases/NoExtraKeys.md +17 -0
- package/api/@xmachines/play-react/README.md +423 -0
- package/api/@xmachines/play-react/classes/PlayErrorBoundary.md +613 -0
- package/api/@xmachines/play-react/functions/useSignalEffect.md +68 -0
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryProps.md +15 -0
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryState.md +14 -0
- package/api/@xmachines/play-react/interfaces/PlayRendererProps.md +15 -0
- package/api/@xmachines/play-react/variables/PlayRenderer.md +64 -0
- package/api/@xmachines/play-react-router/README.md +198 -0
- package/api/@xmachines/play-react-router/classes/ReactRouterBridge.md +321 -0
- package/api/@xmachines/play-react-router/classes/RouteMap.md +137 -0
- package/api/@xmachines/play-react-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-react-router/functions/createRouteMapFromTree.md +35 -0
- package/api/@xmachines/play-react-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-react-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-react-router/interfaces/RouteMapping.md +17 -0
- package/api/@xmachines/play-react-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-react-router-demo/README.md +137 -0
- package/api/@xmachines/play-router/README.md +502 -0
- package/api/@xmachines/play-router/classes/BaseRouteMap.md +142 -0
- package/api/@xmachines/play-router/classes/RouterBridgeBase.md +300 -0
- package/api/@xmachines/play-router/functions/buildRouteTree.md +27 -0
- package/api/@xmachines/play-router/functions/connectRouter.md +67 -0
- package/api/@xmachines/play-router/functions/crawlMachine.md +92 -0
- package/api/@xmachines/play-router/functions/createBrowserHistory.md +47 -0
- package/api/@xmachines/play-router/functions/createRouteMap.md +53 -0
- package/api/@xmachines/play-router/functions/createRouter.md +76 -0
- package/api/@xmachines/play-router/functions/detectDuplicateRoutes.md +32 -0
- package/api/@xmachines/play-router/functions/extractMachineRoutes.md +64 -0
- package/api/@xmachines/play-router/functions/extractRoute.md +45 -0
- package/api/@xmachines/play-router/functions/findRouteById.md +37 -0
- package/api/@xmachines/play-router/functions/findRouteByPath.md +39 -0
- package/api/@xmachines/play-router/functions/getNavigableRoutes.md +35 -0
- package/api/@xmachines/play-router/functions/getRoutableRoutes.md +39 -0
- package/api/@xmachines/play-router/functions/routeExists.md +26 -0
- package/api/@xmachines/play-router/functions/validateRouteFormat.md +29 -0
- package/api/@xmachines/play-router/functions/validateStateExists.md +29 -0
- package/api/@xmachines/play-router/interfaces/BaseRouteMapping.md +27 -0
- package/api/@xmachines/play-router/interfaces/BrowserHistory.md +172 -0
- package/api/@xmachines/play-router/interfaces/BrowserWindow.md +69 -0
- package/api/@xmachines/play-router/interfaces/ConnectRouterOptions.md +13 -0
- package/api/@xmachines/play-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-router/interfaces/RouteInfo.md +19 -0
- package/api/@xmachines/play-router/interfaces/RouteMap.md +56 -0
- package/api/@xmachines/play-router/interfaces/RouteNode.md +21 -0
- package/api/@xmachines/play-router/interfaces/RouteObject.md +21 -0
- package/api/@xmachines/play-router/interfaces/RouteTree.md +20 -0
- package/api/@xmachines/play-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-router/interfaces/StateVisit.md +15 -0
- package/api/@xmachines/play-router/interfaces/VanillaRouter.md +28 -0
- package/api/@xmachines/play-router/type-aliases/RouteMetadata.md +11 -0
- package/api/@xmachines/play-router-demo/README.md +137 -0
- package/api/@xmachines/play-signals/README.md +176 -0
- package/api/@xmachines/play-signals/interfaces/ComputedOptions.md +34 -0
- package/api/@xmachines/play-signals/interfaces/SignalComputed.md +49 -0
- package/api/@xmachines/play-signals/interfaces/SignalOptions.md +35 -0
- package/api/@xmachines/play-signals/interfaces/SignalState.md +68 -0
- package/api/@xmachines/play-signals/interfaces/SignalWatcher.md +97 -0
- package/api/@xmachines/play-signals/namespaces/Signal/README.md +22 -0
- package/api/@xmachines/play-signals/namespaces/Signal/classes/Computed.md +52 -0
- package/api/@xmachines/play-signals/namespaces/Signal/classes/State.md +72 -0
- package/api/@xmachines/play-signals/namespaces/Signal/interfaces/Options.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/README.md +21 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/classes/Watcher.md +85 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/currentComputed.md +13 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSinks.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSources.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSinks.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSources.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/untrack.md +25 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/unwatched.md +9 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/watched.md +9 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isComputed.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isState.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isWatcher.md +19 -0
- package/api/@xmachines/play-signals/type-aliases/WatcherNotify.md +32 -0
- package/api/@xmachines/play-solid/README.md +311 -0
- package/api/@xmachines/play-solid/interfaces/PlayRendererProps.md +15 -0
- package/api/@xmachines/play-solid/variables/PlayRenderer.md +70 -0
- package/api/@xmachines/play-solid-router/README.md +666 -0
- package/api/@xmachines/play-solid-router/classes/RouteMap.md +150 -0
- package/api/@xmachines/play-solid-router/classes/SolidRouterBridge.md +347 -0
- package/api/@xmachines/play-solid-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-solid-router/functions/createRouteMap.md +32 -0
- package/api/@xmachines/play-solid-router/interfaces/AbstractActor.md +486 -0
- package/api/@xmachines/play-solid-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-solid-router/interfaces/RouteMapping.md +14 -0
- package/api/@xmachines/play-solid-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-solid-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-solid-router/type-aliases/SolidRouterHooks.md +51 -0
- package/api/@xmachines/play-solid-router-demo/README.md +127 -0
- package/api/@xmachines/play-tanstack-react-router/README.md +226 -0
- package/api/@xmachines/play-tanstack-react-router/classes/RouteMap.md +137 -0
- package/api/@xmachines/play-tanstack-react-router/classes/TanStackReactRouterBridge.md +348 -0
- package/api/@xmachines/play-tanstack-react-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMap.md +53 -0
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMapFromTree.md +35 -0
- package/api/@xmachines/play-tanstack-react-router/functions/extractParams.md +38 -0
- package/api/@xmachines/play-tanstack-react-router/functions/extractQueryParams.md +33 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteMapping.md +17 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteNavigateEvent.md +26 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterInstance.md +9 -0
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterLike.md +78 -0
- package/api/@xmachines/play-tanstack-react-router/variables/extractMachineRoutes.md +64 -0
- package/api/@xmachines/play-tanstack-react-router-demo/README.md +126 -0
- package/api/@xmachines/play-tanstack-solid-router/README.md +285 -0
- package/api/@xmachines/play-tanstack-solid-router/classes/RouteMap.md +150 -0
- package/api/@xmachines/play-tanstack-solid-router/classes/SolidRouterBridge.md +343 -0
- package/api/@xmachines/play-tanstack-solid-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-tanstack-solid-router/functions/createRouteMap.md +32 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouteMapping.md +23 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterInstance.md +9 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterLike.md +78 -0
- package/api/@xmachines/play-tanstack-solid-router-demo/README.md +126 -0
- package/api/@xmachines/play-vue/README.md +292 -0
- package/api/@xmachines/play-vue/interfaces/PlayRendererProps.md +14 -0
- package/api/@xmachines/play-vue/variables/PlayRenderer.md +9 -0
- package/api/@xmachines/play-vue-router/README.md +604 -0
- package/api/@xmachines/play-vue-router/classes/RouteMap.md +209 -0
- package/api/@xmachines/play-vue-router/classes/VueBaseRouteMap.md +201 -0
- package/api/@xmachines/play-vue-router/classes/VueRouterBridge.md +360 -0
- package/api/@xmachines/play-vue-router/functions/createRouteMap.md +19 -0
- package/api/@xmachines/play-vue-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-vue-router/interfaces/RouteMapping.md +15 -0
- package/api/@xmachines/play-vue-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-vue-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-vue-router/variables/PlayRouterProvider.md +67 -0
- package/api/@xmachines/play-vue-router-demo/README.md +133 -0
- package/api/@xmachines/play-xstate/README.md +512 -0
- package/api/@xmachines/play-xstate/classes/PlayerActor.md +527 -0
- package/api/@xmachines/play-xstate/functions/buildRouteUrl.md +43 -0
- package/api/@xmachines/play-xstate/functions/composeGuards.md +79 -0
- package/api/@xmachines/play-xstate/functions/composeGuardsOr.md +67 -0
- package/api/@xmachines/play-xstate/functions/definePlayer.md +127 -0
- package/api/@xmachines/play-xstate/functions/deriveRoute.md +109 -0
- package/api/@xmachines/play-xstate/functions/eventMatches.md +40 -0
- package/api/@xmachines/play-xstate/functions/formatPlayRouteTransitions.md +54 -0
- package/api/@xmachines/play-xstate/functions/hasContext.md +42 -0
- package/api/@xmachines/play-xstate/functions/isAbsoluteRoute.md +41 -0
- package/api/@xmachines/play-xstate/functions/mergeViewProps.md +26 -0
- package/api/@xmachines/play-xstate/functions/negateGuard.md +61 -0
- package/api/@xmachines/play-xstate/functions/stateMatches.md +25 -0
- package/api/@xmachines/play-xstate/functions/validateComponentBinding.md +39 -0
- package/api/@xmachines/play-xstate/functions/validateViewProps.md +80 -0
- package/api/@xmachines/play-xstate/interfaces/CatalogEntry.md +16 -0
- package/api/@xmachines/play-xstate/interfaces/PlayerConfig.md +24 -0
- package/api/@xmachines/play-xstate/interfaces/PlayerOptions.md +26 -0
- package/api/@xmachines/play-xstate/interfaces/RouteContext.md +22 -0
- package/api/@xmachines/play-xstate/type-aliases/Catalog.md +21 -0
- package/api/@xmachines/play-xstate/type-aliases/ComposedGuard.md +14 -0
- package/api/@xmachines/play-xstate/type-aliases/Guard.md +34 -0
- package/api/@xmachines/play-xstate/type-aliases/GuardArray.md +20 -0
- package/api/@xmachines/play-xstate/type-aliases/PlayerFactory.md +29 -0
- package/api/@xmachines/play-xstate/type-aliases/RouteMachineConfig.md +45 -0
- package/api/@xmachines/play-xstate/type-aliases/RouteStateNode.md +51 -0
- package/api/@xmachines/play-xstate/type-aliases/ValidationResult.md +17 -0
- package/api/@xmachines/play-xstate/type-aliases/ViewMergeContext.md +35 -0
- package/api/@xmachines/shared/README.md +379 -0
- package/api/@xmachines/shared/functions/defineXmVitestConfig.md +29 -0
- package/api/@xmachines/shared/functions/xmAliases.md +24 -0
- package/api/README.md +25 -0
- package/api/llms.txt +26 -0
- package/examples/README.md +63 -0
- package/examples/basic-state-machine.md +70 -0
- package/examples/form-validation.md +167 -0
- package/examples/multi-router-integration.md +277 -0
- package/examples/routing-patterns.md +260 -0
- package/examples/traffic-light.md +99 -0
- package/guides/README.md +29 -0
- package/guides/getting-started.md +223 -0
- package/guides/installation.md +323 -0
- package/index.d.ts +3 -0
- package/index.js +4 -0
- package/package.json +54 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / PlayRouteEvent
|
|
2
|
+
|
|
3
|
+
# Interface: PlayRouteEvent
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:190](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L190)
|
|
6
|
+
|
|
7
|
+
Enhanced routing event with parameter and query support
|
|
8
|
+
|
|
9
|
+
Unified routing event used throughout the Play architecture. Supports parameter-aware
|
|
10
|
+
navigation patterns (e.g., `/profile/:userId`) for dynamic route segments.
|
|
11
|
+
|
|
12
|
+
**Architectural Context:** Implements **Passive Infrastructure (INV-04)** by representing
|
|
13
|
+
user navigation intent that the Actor evaluates through guards. Infrastructure proposes
|
|
14
|
+
via `play.route` events, Actor decides via state machine transitions.
|
|
15
|
+
|
|
16
|
+
**Browser Navigation Flow:**
|
|
17
|
+
|
|
18
|
+
1. Browser fires `popstate`
|
|
19
|
+
2. Router adapter resolves URL to route target
|
|
20
|
+
3. Adapter sends `PlayRouteEvent` to Actor
|
|
21
|
+
4. Actor validates transition via state machine guards
|
|
22
|
+
|
|
23
|
+
## Param
|
|
24
|
+
|
|
25
|
+
Event discriminator (always "play.route")
|
|
26
|
+
|
|
27
|
+
## Param
|
|
28
|
+
|
|
29
|
+
Target state ID with # prefix (e.g., '#home', '#profile')
|
|
30
|
+
|
|
31
|
+
## Param
|
|
32
|
+
|
|
33
|
+
Merged path + query parameters (path parameters win conflicts)
|
|
34
|
+
|
|
35
|
+
## Param
|
|
36
|
+
|
|
37
|
+
Query parameters only (isolated from path params)
|
|
38
|
+
|
|
39
|
+
## Param
|
|
40
|
+
|
|
41
|
+
Full URLPattern match result for debugging/observability (optional)
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
Combining base and routing events
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import type { PlayEvent } from "@xmachines/play";
|
|
49
|
+
import type { PlayRouteEvent } from "@xmachines/play-router";
|
|
50
|
+
|
|
51
|
+
type AppEvent = PlayEvent | PlayRouteEvent;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Basic navigation to a route
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import type { PlayRouteEvent } from "@xmachines/play-router";
|
|
58
|
+
|
|
59
|
+
const event: PlayRouteEvent = {
|
|
60
|
+
type: "play.route",
|
|
61
|
+
to: "#home",
|
|
62
|
+
};
|
|
63
|
+
actor.send(event);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Navigation with route parameters
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import type { PlayRouteEvent } from "@xmachines/play-router";
|
|
70
|
+
|
|
71
|
+
const event: PlayRouteEvent = {
|
|
72
|
+
type: "play.route",
|
|
73
|
+
to: "#profile",
|
|
74
|
+
params: { userId: "123" },
|
|
75
|
+
};
|
|
76
|
+
actor.send(event);
|
|
77
|
+
// Resolves to route: /profile/123
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Navigation with query parameters
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import type { PlayRouteEvent } from "@xmachines/play-router";
|
|
84
|
+
|
|
85
|
+
const event: PlayRouteEvent = {
|
|
86
|
+
type: "play.route",
|
|
87
|
+
to: "#settings",
|
|
88
|
+
params: { section: "profile" }, // Merged: path + query
|
|
89
|
+
query: { tab: "security" }, // Query-only
|
|
90
|
+
};
|
|
91
|
+
actor.send(event);
|
|
92
|
+
// Resolves to route: /settings/profile?tab=security
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## See
|
|
96
|
+
|
|
97
|
+
[RFC Play v1](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md)
|
|
98
|
+
|
|
99
|
+
## Remarks
|
|
100
|
+
|
|
101
|
+
Use `play.route` when you need parameter-aware navigation with the `route: {}`
|
|
102
|
+
config pattern on your state machine nodes. The `match` field exposes the full
|
|
103
|
+
URLPatternResult for advanced use cases (debugging, pattern analysis).
|
|
104
|
+
|
|
105
|
+
## Indexable
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
[key: string]: unknown
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Properties
|
|
112
|
+
|
|
113
|
+
| Property | Modifier | Type | Defined in |
|
|
114
|
+
| -------------------------------------- | ---------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| <a id="property-match"></a> `match?` | `readonly` | `unknown` | [types.ts:195](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L195) |
|
|
116
|
+
| <a id="property-params"></a> `params?` | `readonly` | `Record`\<`string`, `string`\> | [types.ts:193](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L193) |
|
|
117
|
+
| <a id="property-query"></a> `query?` | `readonly` | `Record`\<`string`, `string`\> | [types.ts:194](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L194) |
|
|
118
|
+
| <a id="property-to"></a> `to` | `readonly` | `string` | [types.ts:192](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L192) |
|
|
119
|
+
| <a id="property-type"></a> `type` | `readonly` | `"play.route"` | [types.ts:191](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L191) |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteInfo
|
|
2
|
+
|
|
3
|
+
# Interface: RouteInfo
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:40](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L40)
|
|
6
|
+
|
|
7
|
+
Extracted route information from a state node
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
| Property | Type | Description | Defined in |
|
|
12
|
+
| --------------------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| <a id="property-isabsolute"></a> `isAbsolute` | `boolean` | Whether route path is absolute (starts with /) | [types.ts:50](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L50) |
|
|
14
|
+
| <a id="property-metadata"></a> `metadata` | [`RouteMetadata`](../type-aliases/RouteMetadata.md) | Original route metadata | [types.ts:57](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L57) |
|
|
15
|
+
| <a id="property-pattern"></a> `pattern?` | `string` | Route pattern with parameters (e.g., /profile/:userId) if routePath contains params | [types.ts:48](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L48) |
|
|
16
|
+
| <a id="property-routable"></a> `routable` | `boolean` | Whether this state is routable (has meta.route) true = has meta.route, can receive play.route events | [types.ts:55](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L55) |
|
|
17
|
+
| <a id="property-routepath"></a> `routePath` | `string` | Route path extracted from meta.route | [types.ts:46](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L46) |
|
|
18
|
+
| <a id="property-stateid"></a> `stateId` | `string` | State identifier (node.id or path.join('.')) | [types.ts:42](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L42) |
|
|
19
|
+
| <a id="property-statepath"></a> `statePath` | `string`[] | State path segments from root | [types.ts:44](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L44) |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteMap
|
|
2
|
+
|
|
3
|
+
# Interface: RouteMap
|
|
4
|
+
|
|
5
|
+
Defined in: [create-route-map.ts:27](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-route-map.ts#L27)
|
|
6
|
+
|
|
7
|
+
Bidirectional route resolution interface returned by `createRouteMap()`.
|
|
8
|
+
|
|
9
|
+
Resolves incoming URL paths to state IDs (with `#` prefix) and extracts
|
|
10
|
+
route parameters. Used by `RouterBridgeBase` to translate router navigation
|
|
11
|
+
events into `play.route` actor events.
|
|
12
|
+
|
|
13
|
+
## See
|
|
14
|
+
|
|
15
|
+
- [createRouteMap](../functions/createRouteMap.md) for the factory function
|
|
16
|
+
- [BaseRouteMap](../classes/BaseRouteMap.md) for direct state ID ↔ path lookups without params extraction
|
|
17
|
+
|
|
18
|
+
## Methods
|
|
19
|
+
|
|
20
|
+
### resolve()
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
resolve(path): object;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Defined in: [create-route-map.ts:44](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-route-map.ts#L44)
|
|
27
|
+
|
|
28
|
+
Resolve a URL path to a state ID and params.
|
|
29
|
+
|
|
30
|
+
#### Parameters
|
|
31
|
+
|
|
32
|
+
| Parameter | Type | Description |
|
|
33
|
+
| --------- | -------- | ---------------------------------------- |
|
|
34
|
+
| `path` | `string` | URL pathname (e.g., "/settings/account") |
|
|
35
|
+
|
|
36
|
+
#### Returns
|
|
37
|
+
|
|
38
|
+
`object`
|
|
39
|
+
|
|
40
|
+
Object with `to` (state ID with # prefix) and `params`
|
|
41
|
+
|
|
42
|
+
Example:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const { to, params } = routeMap.resolve("/settings/account");
|
|
46
|
+
// { to: "#settings", params: { section: "account" } }
|
|
47
|
+
|
|
48
|
+
if (to) {
|
|
49
|
+
actor.send({ type: "play.route", to, params });
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Name | Type | Defined in |
|
|
54
|
+
| -------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `params` | `Record`\<`string`, `string`\> | [create-route-map.ts:46](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-route-map.ts#L46) |
|
|
56
|
+
| `to` | `string` \| `null` | [create-route-map.ts:45](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-route-map.ts#L45) |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteNode
|
|
2
|
+
|
|
3
|
+
# Interface: RouteNode
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:63](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L63)
|
|
6
|
+
|
|
7
|
+
Node in the route tree representing a single route
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
| Property | Type | Description | Defined in |
|
|
12
|
+
| ----------------------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| <a id="property-children"></a> `children` | `RouteNode`[] | Child routes | [types.ts:80](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L80) |
|
|
14
|
+
| <a id="property-fullpath"></a> `fullPath` | `string` | Full resolved path from root | [types.ts:69](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L69) |
|
|
15
|
+
| <a id="property-id"></a> `id` | `string` | Unique identifier (state ID) | [types.ts:65](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L65) |
|
|
16
|
+
| <a id="property-metadata"></a> `metadata` | `unknown` | Original meta.route metadata | [types.ts:84](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L84) |
|
|
17
|
+
| <a id="property-parent"></a> `parent` | `RouteNode` \| `null` | Parent route (null for root) | [types.ts:82](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L82) |
|
|
18
|
+
| <a id="property-path"></a> `path` | `string` | Route path segment (relative or absolute) | [types.ts:67](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L67) |
|
|
19
|
+
| <a id="property-pattern"></a> `pattern?` | `string` | Route pattern with parameters (e.g., /profile/:userId) if path contains params | [types.ts:71](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L71) |
|
|
20
|
+
| <a id="property-routable"></a> `routable` | `boolean` | Whether this state is routable (has meta.route) States with meta.route can receive play.route events | [types.ts:78](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L78) |
|
|
21
|
+
| <a id="property-stateid"></a> `stateId` | `string` | XState state ID this route maps to | [types.ts:73](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L73) |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteObject
|
|
2
|
+
|
|
3
|
+
# Interface: RouteObject
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:13](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L13)
|
|
6
|
+
|
|
7
|
+
Route object with additional metadata.
|
|
8
|
+
|
|
9
|
+
## Indexable
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
[key: string]: unknown
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Additional route metadata (title, breadcrumb, etc.)
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
| Property | Type | Description | Defined in |
|
|
20
|
+
| --------------------------------- | -------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| <a id="property-path"></a> `path` | `string` | Route path template (e.g., '/user/:id') | [types.ts:15](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L15) |
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteTree
|
|
2
|
+
|
|
3
|
+
# Interface: RouteTree
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:94](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L94)
|
|
6
|
+
|
|
7
|
+
Complete route tree with lookup maps
|
|
8
|
+
|
|
9
|
+
Provides bidirectional mapping between state IDs and URL paths:
|
|
10
|
+
|
|
11
|
+
- byStateId: Maps state IDs to route nodes (for play.route event targeting)
|
|
12
|
+
- byPath: Maps URL paths to route nodes (for browser navigation)
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
|
|
16
|
+
| Property | Type | Description | Defined in |
|
|
17
|
+
| ------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| <a id="property-bypath"></a> `byPath` | `Map`\<`string`, [`RouteNode`](RouteNode.md)\> | Map full path -> route node Used to look up state ID from URL path for play.route event targeting | [types.ts:106](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L106) |
|
|
19
|
+
| <a id="property-bystateid"></a> `byStateId` | `Map`\<`string`, [`RouteNode`](RouteNode.md)\> | Map state ID -> route node Used to look up URL path from state ID for browser URL sync | [types.ts:101](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L101) |
|
|
20
|
+
| <a id="property-root"></a> `root` | [`RouteNode`](RouteNode.md) | Root route node | [types.ts:96](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L96) |
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouterBridge
|
|
2
|
+
|
|
3
|
+
# Interface: RouterBridge
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:238](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L238)
|
|
6
|
+
|
|
7
|
+
RouterBridge interface for runtime infrastructure adapters
|
|
8
|
+
|
|
9
|
+
Defines the lifecycle connection between Infrastructure (e.g., TanStack Router) and
|
|
10
|
+
the Actor. Infrastructure "bridges" to the Actor by observing its signals and
|
|
11
|
+
managing its own lifecycle accordingly.
|
|
12
|
+
|
|
13
|
+
**Architectural Context:** Implements **Passive Infrastructure (INV-04)** by establishing
|
|
14
|
+
a unidirectional observation pattern. Infrastructure connects to observe Actor signals
|
|
15
|
+
(currentRoute, currentView, state) and reflects changes without making state decisions.
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
TanStack Router bridge implementation
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import type { RouterBridge } from "@xmachines/play-router";
|
|
23
|
+
import { Signal } from "@xmachines/play-signals";
|
|
24
|
+
|
|
25
|
+
class TanStackRouterBridge implements RouterBridge {
|
|
26
|
+
private watcher: Signal.Watcher | null = null;
|
|
27
|
+
|
|
28
|
+
async connect(): Promise<void> {
|
|
29
|
+
// Start observing actor.currentRoute signal
|
|
30
|
+
this.watcher = new Signal.subtle.Watcher(() => {
|
|
31
|
+
const route = actor.currentRoute.get();
|
|
32
|
+
if (route) router.navigate(route);
|
|
33
|
+
});
|
|
34
|
+
this.watcher.watch(actor.currentRoute);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async disconnect(): Promise<void> {
|
|
38
|
+
// Stop observing, cleanup watchers
|
|
39
|
+
this.watcher?.unwatch(actor.currentRoute);
|
|
40
|
+
this.watcher = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## See
|
|
46
|
+
|
|
47
|
+
[RFC Play v1 - Invariant INV-04](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md)
|
|
48
|
+
|
|
49
|
+
## Methods
|
|
50
|
+
|
|
51
|
+
### connect()
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
connect(): void | Promise<void>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Defined in: [types.ts:254](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L254)
|
|
58
|
+
|
|
59
|
+
Connect the router bridge to the Actor
|
|
60
|
+
|
|
61
|
+
Called when Infrastructure should begin observing Actor signals and
|
|
62
|
+
synchronizing its state (e.g., browser URL) with Actor state.
|
|
63
|
+
|
|
64
|
+
#### Returns
|
|
65
|
+
|
|
66
|
+
`void` \| `Promise`\<`void`\>
|
|
67
|
+
|
|
68
|
+
Promise that resolves when connection is established, or void for synchronous connection
|
|
69
|
+
|
|
70
|
+
#### Example
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const bridge: RouterBridge = createBridge(actor, router);
|
|
74
|
+
await bridge.connect();
|
|
75
|
+
// Bridge now observing actor.currentRoute signal
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### disconnect()
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
disconnect(): void | Promise<void>;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Defined in: [types.ts:270](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L270)
|
|
87
|
+
|
|
88
|
+
Disconnect the router bridge from the Actor
|
|
89
|
+
|
|
90
|
+
Called when Infrastructure should stop observing and clean up resources
|
|
91
|
+
(e.g., signal watchers, event listeners).
|
|
92
|
+
|
|
93
|
+
#### Returns
|
|
94
|
+
|
|
95
|
+
`void` \| `Promise`\<`void`\>
|
|
96
|
+
|
|
97
|
+
Promise that resolves when disconnection is complete, or void for synchronous disconnection
|
|
98
|
+
|
|
99
|
+
#### Example
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
await bridge.disconnect();
|
|
103
|
+
// Bridge stopped observing, resources cleaned up
|
|
104
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / StateVisit
|
|
2
|
+
|
|
3
|
+
# Interface: StateVisit
|
|
4
|
+
|
|
5
|
+
Defined in: [types.ts:28](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L28)
|
|
6
|
+
|
|
7
|
+
Represents a visit to a state node during graph crawling
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
| Property | Type | Description | Defined in |
|
|
12
|
+
| ------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| <a id="property-node"></a> `node` | `StateNode` | The state node being visited | [types.ts:30](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L30) |
|
|
14
|
+
| <a id="property-parent"></a> `parent` | `StateNode`\<`MachineContext`, `EventObject`\> \| `null` | Parent state node (null for root) | [types.ts:34](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L34) |
|
|
15
|
+
| <a id="property-path"></a> `path` | `string`[] | Path from root to this state (e.g., ['dashboard', 'overview']) | [types.ts:32](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L32) |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / VanillaRouter
|
|
2
|
+
|
|
3
|
+
# Interface: VanillaRouter
|
|
4
|
+
|
|
5
|
+
Defined in: [create-router.ts:4](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-router.ts#L4)
|
|
6
|
+
|
|
7
|
+
## Properties
|
|
8
|
+
|
|
9
|
+
| Property | Modifier | Type | Description | Defined in |
|
|
10
|
+
| ------------------------------------------- | ---------- | ------------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| <a id="property-history"></a> `history` | `readonly` | [`BrowserHistory`](BrowserHistory.md) | History instance | [create-router.ts:8](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-router.ts#L8) |
|
|
12
|
+
| <a id="property-routetree"></a> `routeTree` | `readonly` | [`RouteTree`](RouteTree.md) | Route tree (for structure reference) | [create-router.ts:13](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-router.ts#L13) |
|
|
13
|
+
|
|
14
|
+
## Methods
|
|
15
|
+
|
|
16
|
+
### destroy()
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
destroy(): void;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Defined in: [create-router.ts:18](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/create-router.ts#L18)
|
|
23
|
+
|
|
24
|
+
Cleanup
|
|
25
|
+
|
|
26
|
+
#### Returns
|
|
27
|
+
|
|
28
|
+
`void`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-router](../README.md) / RouteMetadata
|
|
2
|
+
|
|
3
|
+
# Type Alias: RouteMetadata
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type RouteMetadata = string | RouteObject;
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:23](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-router/src/types.ts#L23)
|
|
10
|
+
|
|
11
|
+
Route metadata from state machine `meta.route` field.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
[Documentation](../../README.md) / @xmachines/play-router-demo
|
|
2
|
+
|
|
3
|
+
# Vanilla JavaScript Router Demo
|
|
4
|
+
|
|
5
|
+
Pure JavaScript integration proving Play Architecture works without any framework.
|
|
6
|
+
|
|
7
|
+
## What This Demonstrates
|
|
8
|
+
|
|
9
|
+
This demo uses **no framework** - just vanilla JavaScript with the Browser History API and DOM manipulation. It proves that Play Architecture's universal abstractions work at the lowest level, making framework integrations simpler by comparison.
|
|
10
|
+
|
|
11
|
+
## Key Features
|
|
12
|
+
|
|
13
|
+
- **Zero Framework Dependencies**: Pure JavaScript and DOM
|
|
14
|
+
- **Browser History API**: Direct integration with `window.history`
|
|
15
|
+
- **Same Auth Machine**: Identical authentication logic as React/Vue/SolidJS demos
|
|
16
|
+
- **Reference Implementation**: This demo serves as the visual reference for all framework demos
|
|
17
|
+
|
|
18
|
+
## Running the Demo
|
|
19
|
+
|
|
20
|
+
From the repository root:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
npm run dev -w packages/play-router/examples/demo
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Visit `http://localhost:5174`.
|
|
28
|
+
|
|
29
|
+
## Step-by-Step Code Flow
|
|
30
|
+
|
|
31
|
+
Use this order to understand the demo implementation:
|
|
32
|
+
|
|
33
|
+
1. `src/main.ts` creates the actor from the shared machine/catalog and starts it.
|
|
34
|
+
2. `src/router.ts` extracts machine routes, builds browser-history routing primitives, and connects actor <-> router sync.
|
|
35
|
+
3. `src/shell.ts` subscribes to actor signals and renders state-projected DOM views.
|
|
36
|
+
4. Navigation and auth interactions dispatch actor events (`play.route`, `auth.login`, `auth.logout`) rather than mutating URL/state directly.
|
|
37
|
+
5. Browser tests in `test/browser/` validate startup rendering and the auth route flow end-to-end.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// src/main.ts (shape)
|
|
41
|
+
const actor = createActorFromSharedMachine();
|
|
42
|
+
actor.start();
|
|
43
|
+
|
|
44
|
+
const cleanupRouter = initRouter(actor);
|
|
45
|
+
const app = document.getElementById("app");
|
|
46
|
+
if (app) {
|
|
47
|
+
initShell(actor, app);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// src/router.ts (shape)
|
|
53
|
+
const routeTree = extractMachineRoutes(machine);
|
|
54
|
+
const routeMap = createRouteMap(routeTree);
|
|
55
|
+
const history = createBrowserHistory();
|
|
56
|
+
const router = createRouter({ history, routeMap });
|
|
57
|
+
connectRouter({ actor, router, routeMap });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// src/shell.ts (shape)
|
|
62
|
+
actor.currentView.watch(() => {
|
|
63
|
+
renderView(actor.currentView.get());
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
loginButton.onclick = () => actor.send({ type: "auth.login", username, password });
|
|
67
|
+
logoutButton.onclick = () => actor.send({ type: "auth.logout" });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Key Files
|
|
71
|
+
|
|
72
|
+
- `src/main.ts` - actor startup, router initialization, and shell bootstrap
|
|
73
|
+
- `src/router.ts` - `createBrowserHistory`, `createRouter`, and `connectRouter` wiring
|
|
74
|
+
- `src/shell.ts` - DOM rendering and reactive watcher loop for state-driven updates
|
|
75
|
+
- `test/browser/startup.browser.test.ts` - startup rendering assertion for public home + login action
|
|
76
|
+
- `test/browser/auth-flow.browser.test.ts` - login -> dashboard -> profile -> logout browser flow
|
|
77
|
+
|
|
78
|
+
## State Machine & Architecture Details
|
|
79
|
+
|
|
80
|
+
The demo utilizes XMachines architectural invariants at the lowest level:
|
|
81
|
+
|
|
82
|
+
1. **Actor Authority:** Intercepting browser `popstate` events or link clicks dispatches a `play.route` event to the actor. The actor processes the request against the current state, ensuring any auth logic is correctly applied.
|
|
83
|
+
2. **Passive Infrastructure:** The router simply updates `window.history` and the DOM solely renders HTML text based on what `actor.currentView.get()` yields.
|
|
84
|
+
3. **Signal-Only Reactivity:** The integration registers manual `Signal.subtle.Watcher` observers that manually trigger DOM reconciliation, illustrating the underlying mechanism abstraction used by framework adapters.
|
|
85
|
+
|
|
86
|
+
## Watcher Lifecycle and Cleanup Contract
|
|
87
|
+
|
|
88
|
+
Even in the vanilla demo, watcher handling follows the same canonical lifecycle:
|
|
89
|
+
|
|
90
|
+
1. `notify`
|
|
91
|
+
2. `queueMicrotask`
|
|
92
|
+
3. `getPending()`
|
|
93
|
+
4. Read actor signals and project DOM state
|
|
94
|
+
5. Re-arm with `watch()`/`watch(...signals)`
|
|
95
|
+
|
|
96
|
+
Watcher notifications are one-shot, so re-arm is mandatory. Router/shell teardown must explicitly call cleanup (`disconnect`/`unwatch`) and not rely on GC-only behavior. In vanilla JS, this means retaining the cleanup functions and calling them during hot-module replacement or app unmount.
|
|
97
|
+
|
|
98
|
+
## Adapter Boundaries
|
|
99
|
+
|
|
100
|
+
`connectRouter` and browser-history wiring are passive infrastructure. Actor logic remains authoritative for route validity, and shared synchronization policy stays in `RouterBridgeBase` for framework bridges.
|
|
101
|
+
|
|
102
|
+
## Why Vanilla?
|
|
103
|
+
|
|
104
|
+
Vanilla JavaScript is the foundation:
|
|
105
|
+
|
|
106
|
+
- **Universal Patterns**: If it works in vanilla, frameworks are just convenience layers
|
|
107
|
+
- **No Magic**: Every interaction is explicit - great for learning
|
|
108
|
+
- **Performance Baseline**: Shows the minimal overhead of Play Architecture
|
|
109
|
+
|
|
110
|
+
This demo proves frameworks aren't required for Play Architecture to work.
|
|
111
|
+
|
|
112
|
+
## Available Scripts
|
|
113
|
+
|
|
114
|
+
These commands are defined in `package.json`:
|
|
115
|
+
|
|
116
|
+
| Command | Description |
|
|
117
|
+
| ------------------------------------------------------------ | -------------------------------- |
|
|
118
|
+
| `npm run dev -w packages/play-router/examples/demo` | Start Vite dev server |
|
|
119
|
+
| `npm run build -w packages/play-router/examples/demo` | Build production bundle |
|
|
120
|
+
| `npm run preview -w packages/play-router/examples/demo` | Preview built bundle |
|
|
121
|
+
| `npm run test -w packages/play-router/examples/demo` | Run Vitest test suite |
|
|
122
|
+
| `npm run test:browser -w packages/play-router/examples/demo` | Run browser-focused Vitest suite |
|
|
123
|
+
|
|
124
|
+
## Verification
|
|
125
|
+
|
|
126
|
+
Validate the operational behavior with package-local tests:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm run test -w packages/play-router/examples/demo
|
|
130
|
+
npm run test:browser -w packages/play-router/examples/demo
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Expected result: tests pass, including startup rendering and the full browser auth flow in `test/browser/`.
|
|
134
|
+
|
|
135
|
+
## Learn More
|
|
136
|
+
|
|
137
|
+
- **[Play Router Package README](../play-router/README.md)** - Router APIs and integration patterns
|