@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikael Karon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @xmachines/docs
|
|
2
|
+
|
|
3
|
+
This package contains the generated Typedoc documentation for the `xmachines-js` monorepo.
|
|
4
|
+
|
|
5
|
+
The documentation is automatically built and published from the source code.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
You can browse the documentation online at [https://xmachin.es/docs](https://xmachin.es/docs) (once published).
|
|
10
|
+
|
|
11
|
+
To build the documentation locally:
|
|
12
|
+
|
|
13
|
+
1. Clone the `xmachines-js` monorepo.
|
|
14
|
+
2. Run `npm install` in the root directory.
|
|
15
|
+
3. Run `npm run docs` to generate the documentation into `packages/docs/api`.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
[Documentation](../../README.md) / @xmachines/play
|
|
2
|
+
|
|
3
|
+
# @xmachines/play
|
|
4
|
+
|
|
5
|
+
**Protocol layer defining Actor ↔ Infrastructure event contracts for XMachines Play Architecture.**
|
|
6
|
+
|
|
7
|
+
`@xmachines/play` is intentionally small. It provides the base event contract used across adapters and actor implementations while keeping framework/runtime concerns out of business logic.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This package exports protocol types only (no runtime behavior). It exists to preserve strict separation between:
|
|
12
|
+
|
|
13
|
+
- **Actors** (business authority)
|
|
14
|
+
- **Infrastructure adapters** (routers/renderers that observe and forward)
|
|
15
|
+
|
|
16
|
+
Per [RFC Play v1](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md), this package supports:
|
|
17
|
+
|
|
18
|
+
- **Actor Authority (INV-01):** infrastructure proposes intents, actor decides validity
|
|
19
|
+
- **Strict Separation (INV-02):** protocol types are framework-agnostic
|
|
20
|
+
- **Passive Infrastructure (INV-04):** adapters reflect actor decisions
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @xmachines/play
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Surface
|
|
29
|
+
|
|
30
|
+
This package exports:
|
|
31
|
+
|
|
32
|
+
- `PlayEvent<TPayload>`
|
|
33
|
+
|
|
34
|
+
`PlayEvent` is the minimal event shape:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
type PlayEvent<TPayload extends Record<string, any> = Record<string, any>> = {
|
|
38
|
+
readonly type: string;
|
|
39
|
+
} & TPayload;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Base event usage
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import type { PlayEvent } from "@xmachines/play";
|
|
48
|
+
|
|
49
|
+
type LoginEvent = PlayEvent<{ userId: string }>;
|
|
50
|
+
|
|
51
|
+
const event: LoginEvent = {
|
|
52
|
+
type: "auth.login",
|
|
53
|
+
userId: "user-123",
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Architecture Notes
|
|
58
|
+
|
|
59
|
+
- Keep `@xmachines/play` as the base protocol boundary.
|
|
60
|
+
- Keep actor implementation details in adapter packages such as `@xmachines/play-xstate`.
|
|
61
|
+
|
|
62
|
+
## Related Packages
|
|
63
|
+
|
|
64
|
+
- [@xmachines/play-actor](../play-actor/README.md)
|
|
65
|
+
- [@xmachines/play-xstate](../play-xstate/README.md)
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
Copyright (c) 2016 [Mikael Karon](mailto:mikael@karon.se). All rights reserved.
|
|
70
|
+
|
|
71
|
+
This work is licensed under the terms of the MIT license.
|
|
72
|
+
For a copy, see <https://opensource.org/licenses/MIT>.
|
|
73
|
+
|
|
74
|
+
@xmachines/play - Core Protocol Layer
|
|
75
|
+
|
|
76
|
+
Defines architectural contracts enabling Actor ↔ Infrastructure communication
|
|
77
|
+
without direct dependencies. Per RFC section 5.2, these protocols establish
|
|
78
|
+
the foundation for loose coupling between business logic and runtime adapters.
|
|
79
|
+
|
|
80
|
+
## Exports
|
|
81
|
+
|
|
82
|
+
**PlayEvent<TPayload>** - Generic event type for Actor communication
|
|
83
|
+
|
|
84
|
+
- Any object with a `type: string` property
|
|
85
|
+
- Generic `TPayload` parameter for type-safe event shapes (optional)
|
|
86
|
+
- Defaults to `Record<string, unknown>` for maximum flexibility
|
|
87
|
+
- Framework-agnostic (not tied to XState or any specific library)
|
|
88
|
+
|
|
89
|
+
**Usage:**
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Flexible (default):
|
|
93
|
+
const event: PlayEvent = { type: "auth.login", userId: "123" };
|
|
94
|
+
|
|
95
|
+
// Type-safe (with generic):
|
|
96
|
+
type LoginEvent = PlayEvent<{ userId: string }>;
|
|
97
|
+
const event: LoginEvent = { type: "auth.login", userId: "123" };
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Common Event Patterns:**
|
|
101
|
+
|
|
102
|
+
- Domain events: `{ type: 'auth.login', userId: '123' }`
|
|
103
|
+
- Custom events: `{ type: 'form.submit', data: {...} }`
|
|
104
|
+
|
|
105
|
+
**Routing Events** are provided by @xmachines/play-router:
|
|
106
|
+
|
|
107
|
+
- PlayRouteEvent: Enhanced routing with parameters and state ID targeting
|
|
108
|
+
- RouterBridge: Protocol for router adapters to connect with actors
|
|
109
|
+
|
|
110
|
+
**Browser Navigation:** Browser back/forward buttons are handled by router adapters
|
|
111
|
+
via the `popstate` event. When users press back/forward, the router detects the URL
|
|
112
|
+
change and sends a PlayRouteEvent to the actor for validation.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import type { PlayRouteEvent, RouterBridge } from "@xmachines/play-router";
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Architectural Invariants
|
|
119
|
+
|
|
120
|
+
These protocols enforce the following invariants:
|
|
121
|
+
|
|
122
|
+
1. **Actor Authority**: Infrastructure proposes intents, Actor decides validity
|
|
123
|
+
2. **Strict Separation**: No direct dependencies between layers
|
|
124
|
+
3. **Passive Infrastructure**: Infrastructure observes Actor signals, never controls
|
|
125
|
+
4. **Signal-Only Reactivity**: All state changes flow through TC39 Signals
|
|
126
|
+
5. **State-Driven Reset**: Navigation follows state machine transition rules
|
|
127
|
+
|
|
128
|
+
## Type Aliases
|
|
129
|
+
|
|
130
|
+
- [PlayEvent](type-aliases/PlayEvent.md)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play](../README.md) / PlayEvent
|
|
2
|
+
|
|
3
|
+
# Type Alias: PlayEvent\<TPayload\>
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type PlayEvent<TPayload> = object & TPayload;
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:69](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play/src/types.ts#L69)
|
|
10
|
+
|
|
11
|
+
Generic event type for Play Architecture
|
|
12
|
+
|
|
13
|
+
PlayEvent represents the minimal event contract for Actor communication: any object
|
|
14
|
+
with a `type` string property. Infrastructure forwards events to the Actor, and the
|
|
15
|
+
Actor's state machine guards determine validity.
|
|
16
|
+
|
|
17
|
+
**Type Parameter:** The generic `TPayload` allows specifying the shape of additional
|
|
18
|
+
event fields beyond `type`. It defaults to `Record<string, unknown>` for maximum flexibility.
|
|
19
|
+
|
|
20
|
+
**Architectural Context:** Implements **Passive Infrastructure (INV-04)** where
|
|
21
|
+
infrastructure reflects user actions as events without making decisions. The Actor's
|
|
22
|
+
state machine guards determine whether each event is valid from the current state.
|
|
23
|
+
|
|
24
|
+
**Framework Agnostic:** This type is intentionally generic and not tied to any
|
|
25
|
+
specific state machine framework. It matches the common event shape used by XState,
|
|
26
|
+
Robot, and other state machine libraries.
|
|
27
|
+
|
|
28
|
+
**Common Event Types:**
|
|
29
|
+
|
|
30
|
+
- Domain events: `{ type: 'auth.login', userId: '123' }`
|
|
31
|
+
- Custom events: `{ type: 'form.submit', data: {...} }`
|
|
32
|
+
|
|
33
|
+
## Type Declaration
|
|
34
|
+
|
|
35
|
+
| Name | Type | Defined in |
|
|
36
|
+
| ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `type` | `string` | [types.ts:70](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play/src/types.ts#L70) |
|
|
38
|
+
|
|
39
|
+
## Type Parameters
|
|
40
|
+
|
|
41
|
+
| Type Parameter | Default type | Description |
|
|
42
|
+
| ---------------------------------------------------- | ------------------------------- | ----------------------------------------------------------------------- |
|
|
43
|
+
| `TPayload` _extends_ `Record`\<`string`, `unknown`\> | `Record`\<`string`, `unknown`\> | Additional fields beyond `type` (defaults to `Record<string, unknown>`) |
|
|
44
|
+
|
|
45
|
+
## Examples
|
|
46
|
+
|
|
47
|
+
Using without type parameter (flexible)
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import type { PlayEvent } from "@xmachines/play";
|
|
51
|
+
|
|
52
|
+
// Accepts any event with type: string
|
|
53
|
+
const loginEvent: PlayEvent = {
|
|
54
|
+
type: "auth.login",
|
|
55
|
+
userId: "user123",
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
};
|
|
58
|
+
actor.send(loginEvent);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Using with type parameter (type-safe)
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import type { PlayEvent } from "@xmachines/play";
|
|
65
|
+
|
|
66
|
+
// Type-safe event with known shape
|
|
67
|
+
type LoginEvent = PlayEvent<{ userId: string; timestamp: number }>;
|
|
68
|
+
|
|
69
|
+
const loginEvent: LoginEvent = {
|
|
70
|
+
type: "auth.login",
|
|
71
|
+
userId: "user123",
|
|
72
|
+
timestamp: Date.now(),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// TypeScript error: missing required field
|
|
76
|
+
const invalid: LoginEvent = { type: "auth.login" }; // Error!
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## See
|
|
80
|
+
|
|
81
|
+
[RFC Play v1](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md)
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
[Documentation](../../README.md) / @xmachines/play-actor
|
|
2
|
+
|
|
3
|
+
# @xmachines/play-actor
|
|
4
|
+
|
|
5
|
+
**Abstract Actor base class with signal protocol for XMachines Play Architecture**
|
|
6
|
+
|
|
7
|
+
Foundation for all actor implementations, enforcing XState compatibility and reactive signal contracts.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`@xmachines/play-actor` provides `AbstractActor`, a base class that extends XState's `Actor` while enforcing the Play Architecture's signal protocol. It maintains XState ecosystem compatibility (inspection tools, devtools) while exposing reactive signals for infrastructure layer communication.
|
|
12
|
+
|
|
13
|
+
Per [RFC Play v1](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md), this package implements:
|
|
14
|
+
|
|
15
|
+
- **Actor Authority (INV-01):** Actor is sole source of truth for state transitions
|
|
16
|
+
- **Signal-Only Reactivity (INV-05):** Infrastructure observes via TC39 Signals, never directly queries
|
|
17
|
+
- **Passive Infrastructure (INV-04):** Infrastructure reflects, never decides
|
|
18
|
+
|
|
19
|
+
**Note:** This is an abstract base class. Concrete implementations are provided by adapters (see [@xmachines/play-xstate](../play-xstate/README.md)).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install xstate@^5.0.0
|
|
25
|
+
npm install @xmachines/play-actor
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Current Exports
|
|
29
|
+
|
|
30
|
+
- `AbstractActor`
|
|
31
|
+
- `Routable` (type)
|
|
32
|
+
- `Viewable` (type)
|
|
33
|
+
|
|
34
|
+
**Peer dependencies:**
|
|
35
|
+
|
|
36
|
+
- `xstate` ^5.0.0 — State machine runtime (XState compatibility)
|
|
37
|
+
- `@xmachines/play-signals` - TC39 Signals primitives
|
|
38
|
+
- `@xmachines/play` - Protocol types (PlayEvent, etc.)
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
**Usage:** This is an abstract base class — use concrete implementations:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { definePlayer } from "@xmachines/play-xstate";
|
|
46
|
+
|
|
47
|
+
// definePlayer returns PlayerActor (extends AbstractActor)
|
|
48
|
+
const createPlayer = definePlayer({ machine, catalog });
|
|
49
|
+
const actor = createPlayer();
|
|
50
|
+
actor.start();
|
|
51
|
+
|
|
52
|
+
// Signal protocol properties (from AbstractActor)
|
|
53
|
+
console.log(actor.state.get()); // Current snapshot
|
|
54
|
+
console.log(actor.currentRoute.get()); // Derived route
|
|
55
|
+
console.log(actor.currentView.get()); // Derived view structure
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### AbstractActor<TLogic>
|
|
61
|
+
|
|
62
|
+
Abstract base class defining signal protocol:
|
|
63
|
+
|
|
64
|
+
**Abstract Properties (must implement):**
|
|
65
|
+
|
|
66
|
+
- `state: Signal.State<unknown>` - Reactive snapshot of current state
|
|
67
|
+
|
|
68
|
+
**Optional capability interfaces:**
|
|
69
|
+
|
|
70
|
+
Implement `Routable` to add routing support:
|
|
71
|
+
|
|
72
|
+
- `currentRoute: Signal.Computed<string | null>` - Derived navigation path
|
|
73
|
+
|
|
74
|
+
Implement `Viewable` to add view rendering support:
|
|
75
|
+
|
|
76
|
+
- `currentView: Signal.State<ViewMetadata | null>` - Current UI structure (updated at state entry)
|
|
77
|
+
- `catalog: Record<string, unknown>` - Component catalog
|
|
78
|
+
|
|
79
|
+
**Inherited from XState Actor:**
|
|
80
|
+
|
|
81
|
+
- `send(event): void` - Send event to actor
|
|
82
|
+
- `start(): void` - Start the actor
|
|
83
|
+
- `stop(): void` - Stop the actor
|
|
84
|
+
- `getSnapshot()` - Get current XState snapshot (typed as `SnapshotFrom<TLogic>`)
|
|
85
|
+
|
|
86
|
+
**Example implementation pattern:**
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { AbstractActor, type Routable, type Viewable, type ViewMetadata } from "@xmachines/play-actor";
|
|
90
|
+
import { Signal } from "@xmachines/play-signals";
|
|
91
|
+
import type { AnyActorLogic, AnyMachineSnapshot } from "xstate";
|
|
92
|
+
|
|
93
|
+
class PlayerActor<TLogic extends AnyActorLogic>
|
|
94
|
+
extends AbstractActor<TLogic>
|
|
95
|
+
implements Routable, Viewable
|
|
96
|
+
{
|
|
97
|
+
// Required: reactive state snapshot
|
|
98
|
+
state = new Signal.State<AnyMachineSnapshot>(this.getSnapshot() as AnyMachineSnapshot);
|
|
99
|
+
|
|
100
|
+
// Routable: derived navigation path
|
|
101
|
+
currentRoute = new Signal.Computed(() => {
|
|
102
|
+
return deriveRoute(this.state.get());
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Viewable: current UI structure — Signal.State, updated at state entry (not computed)
|
|
106
|
+
currentView = new Signal.State<ViewMetadata | null>(null);
|
|
107
|
+
|
|
108
|
+
// Viewable: component catalog
|
|
109
|
+
catalog: Record<string, unknown>;
|
|
110
|
+
|
|
111
|
+
constructor(logic: TLogic, catalog: Record<string, unknown>) {
|
|
112
|
+
super(logic);
|
|
113
|
+
this.catalog = catalog;
|
|
114
|
+
|
|
115
|
+
// Subscribe to XState transitions and update signals
|
|
116
|
+
this.subscribe((snapshot) => {
|
|
117
|
+
this.state.set(snapshot as AnyMachineSnapshot);
|
|
118
|
+
// Update currentView based on snapshot meta...
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
### Infrastructure Observing Signals
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { AbstractActor } from "@xmachines/play-actor";
|
|
131
|
+
import { Signal } from "@xmachines/play-signals";
|
|
132
|
+
|
|
133
|
+
function syncUrlToActor(actor: AbstractActor<any>) {
|
|
134
|
+
// Infrastructure passively observes actor's route signal
|
|
135
|
+
const watcher = new Signal.subtle.Watcher(() => {
|
|
136
|
+
queueMicrotask(() => {
|
|
137
|
+
const pending = watcher.getPending();
|
|
138
|
+
if (pending.length > 0) {
|
|
139
|
+
const route = actor.currentRoute.get();
|
|
140
|
+
if (route !== null) {
|
|
141
|
+
// Update browser URL (Passive Infrastructure)
|
|
142
|
+
window.history.replaceState(null, "", route);
|
|
143
|
+
}
|
|
144
|
+
watcher.watch(...pending); // Re-watch
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
watcher.watch(actor.currentRoute);
|
|
150
|
+
actor.currentRoute.get(); // Initial read
|
|
151
|
+
|
|
152
|
+
return () => watcher.unwatch(actor.currentRoute);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Browser Navigation Sending Events
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { AbstractActor } from "@xmachines/play-actor";
|
|
160
|
+
|
|
161
|
+
function connectBrowserNavigation(actor: AbstractActor<any>) {
|
|
162
|
+
const handlePopstate = () => {
|
|
163
|
+
const path = window.location.pathname;
|
|
164
|
+
|
|
165
|
+
// Browser event sent to actor (Actor Authority)
|
|
166
|
+
// Actor guards decide if navigation is valid
|
|
167
|
+
actor.send({ type: "play.route", to: path });
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
window.addEventListener("popstate", handlePopstate);
|
|
171
|
+
|
|
172
|
+
return () => {
|
|
173
|
+
window.removeEventListener("popstate", handlePopstate);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Architecture
|
|
179
|
+
|
|
180
|
+
This base class enforces three architectural invariants:
|
|
181
|
+
|
|
182
|
+
1. **Actor Authority (INV-01):**
|
|
183
|
+
- Actor decides all state transitions via guards
|
|
184
|
+
- Infrastructure sends events, actor validates and processes
|
|
185
|
+
- Actor's decision is final — no override by infrastructure
|
|
186
|
+
|
|
187
|
+
2. **Signal-Only Reactivity (INV-05):**
|
|
188
|
+
- All reactive state exposed via TC39 Signals
|
|
189
|
+
- Infrastructure uses `Signal.subtle.Watcher` to observe
|
|
190
|
+
- No direct queries (`getSnapshot()` for internal use only)
|
|
191
|
+
|
|
192
|
+
3. **Passive Infrastructure (INV-04):**
|
|
193
|
+
- Infrastructure reflects actor state (via signals)
|
|
194
|
+
- Infrastructure never decides transitions
|
|
195
|
+
- Browser/router events sent as commands to actor
|
|
196
|
+
|
|
197
|
+
## XState Compatibility
|
|
198
|
+
|
|
199
|
+
`AbstractActor` extends XState's `Actor<TLogic>` to maintain:
|
|
200
|
+
|
|
201
|
+
- **Type Safety:** Generic `TLogic extends AnyActorLogic` parameter
|
|
202
|
+
- **Inspection API:** XState Inspector can attach to actors
|
|
203
|
+
- **DevTools Integration:** Standard XState devtools work
|
|
204
|
+
- **Ecosystem Tools:** Works with XState visualization, testing libraries
|
|
205
|
+
|
|
206
|
+
**Snapshot Format:** Standard XState snapshots (state + context) remain unchanged — signals are accessible via actor properties, not snapshots.
|
|
207
|
+
|
|
208
|
+
## Related Packages
|
|
209
|
+
|
|
210
|
+
- **[@xmachines/play-xstate](../play-xstate/README.md)** - Concrete PlayerActor implementation
|
|
211
|
+
- **[@xmachines/play-signals](../play-signals/README.md)** - TC39 Signals primitives
|
|
212
|
+
- **[@xmachines/play](../play/README.md)** - Protocol types (PlayEvent, RouterBridge)
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
Copyright (c) 2016 [Mikael Karon](mailto:mikael@karon.se). All rights reserved.
|
|
217
|
+
|
|
218
|
+
This work is licensed under the terms of the MIT license.
|
|
219
|
+
For a copy, see <https://opensource.org/licenses/MIT>.
|
|
220
|
+
|
|
221
|
+
@xmachines/play-actor - Abstract Actor base class for Play Architecture
|
|
222
|
+
|
|
223
|
+
This package provides AbstractActor, a minimal base class that extends XState Actor
|
|
224
|
+
while enforcing the Play Architecture's signal protocol (RFC section 5.3).
|
|
225
|
+
|
|
226
|
+
The core protocol is minimal (state + send). Optional capabilities are provided
|
|
227
|
+
via interfaces:
|
|
228
|
+
|
|
229
|
+
- Routable: For actors that support routing
|
|
230
|
+
- Viewable: For actors that support view rendering
|
|
231
|
+
|
|
232
|
+
Maintains XState ecosystem compatibility (inspection, devtools) while exposing
|
|
233
|
+
reactive signals for Infrastructure layer communication.
|
|
234
|
+
|
|
235
|
+
## See
|
|
236
|
+
|
|
237
|
+
[RFC Play v1 Section 5.3](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md#53-actor-protocol)
|
|
238
|
+
|
|
239
|
+
## Classes
|
|
240
|
+
|
|
241
|
+
- [AbstractActor](classes/AbstractActor.md)
|
|
242
|
+
|
|
243
|
+
## Interfaces
|
|
244
|
+
|
|
245
|
+
- [Routable](interfaces/Routable.md)
|
|
246
|
+
- [Viewable](interfaces/Viewable.md)
|
|
247
|
+
- [ViewMetadata](interfaces/ViewMetadata.md)
|