@typeonce/effect-machine 0.43.0 → 0.44.0

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.
@@ -47,7 +47,9 @@ import { createMachineContext } from "@typeonce/effect-machine-react"
47
47
  import { AuthMachine } from "../machines/auth-machine"
48
48
  import { MachineAtoms } from "../lib/atom-runtime"
49
49
 
50
- export const Auth = createMachineContext(MachineAtoms.factory(AuthMachine))
50
+ export const Auth = createMachineContext(({ input }: { input: AuthInput }) =>
51
+ MachineAtoms.make(AuthMachine, input)
52
+ )
51
53
  export const useAuthMachine = Auth.useMachine
52
54
 
53
55
  function AuthRoute({ input, attemptId }: Props) {
@@ -59,6 +61,9 @@ function AuthRoute({ input, attemptId }: Props) {
59
61
  }
60
62
  ```
61
63
 
64
+ The factory takes one options object, and each option it declares is a
65
+ Provider prop of the same name and type. A machine without input can pass
66
+ `MachineAtoms.factory(Machine)` directly, and its Provider takes no `input`.
62
67
  Input is startup-only. Send events to update the existing workflow; change the
63
68
  Provider's React key to create a new one. `MachineState` does not suspend, so
64
69
  the first paint needs no Suspense boundary. Custom readers that use
@@ -135,9 +140,9 @@ once. `Atom.runtime` builds layers through the registry's memo map: the shared
135
140
  own capability layer. Use `Layer.provideMerge(ownerLayer, AppLayer)` when the
136
141
  owner layer itself needs application services.
137
142
 
138
- To share the owner-bound machine with a subtree, declare the capability as the
139
- second, `Layer`-typed parameter of a `createMachineContext` factory. The first
140
- parameter is the startup input; `OnboardingMachine` has none, so it is `void`:
143
+ To share the owner-bound machine with a subtree, declare the capability as a
144
+ `layer` option of a `createMachineContext` factory. `OnboardingMachine` has no
145
+ input, so the factory declares only `layer`:
141
146
 
142
147
  ```tsx
143
148
  import { createMachineContext } from "@typeonce/effect-machine-react"
@@ -148,9 +153,9 @@ const navigationLayer = (router: Router) =>
148
153
  })
149
154
 
150
155
  export const Onboarding = createMachineContext(
151
- (_: void, navigation: Layer.Layer<Navigation>) =>
156
+ ({ layer }: { layer: Layer.Layer<Navigation> }) =>
152
157
  AtomMachine
153
- .bind(Atom.runtime(Layer.provideMerge(navigation, AppLayer)))
158
+ .bind(Atom.runtime(Layer.provideMerge(layer, AppLayer)))
154
159
  .make(OnboardingMachine)
155
160
  )
156
161
 
@@ -164,13 +169,15 @@ function OnboardingRoute() {
164
169
  ```
165
170
 
166
171
  The Provider requires a `layer` prop of exactly the declared `Layer` type, and
167
- an `input` prop when the first parameter is the machine's input, as in
168
- `(input: SignInInput, navigation: Layer.Layer<Navigation>)`. A factory without
169
- a layer parameter has a Provider without a `layer` prop. Like `input`, the
170
- layer is read once, when the Provider mounts: a new router instance does not
171
- rebuild the running machine. Change the Provider's React `key` to create a new
172
- owner with a new layer. Binding still checks the machine's requirements, so a
173
- layer type that omits `Navigation` is a compile error.
172
+ an `input` prop when the factory also declares input, as in
173
+ `({ input, layer }: { input: SignInInput; layer: Layer.Layer<Navigation> })`.
174
+ Options other than `input` and `layer` are rejected, so a capability cannot
175
+ travel under another name. A factory without a `layer` option has a Provider
176
+ without a `layer` prop. Like `input`, the layer is read once, when the Provider
177
+ mounts: a new router instance does not rebuild the running machine. Change the
178
+ Provider's React `key` to create a new owner with a new layer. Binding still
179
+ checks the machine's requirements, so a layer type that omits `Navigation` is a
180
+ compile error.
174
181
 
175
182
  ## Render state-owned data
176
183
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/effect-machine",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "description": "Schema-first state machines and statecharts for Effect",
5
5
  "author": "Sandro Maglione",
6
6
  "repository": {