xstate 5.0.0-alpha.0 → 5.0.0-alpha.2

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.
Files changed (97) hide show
  1. package/README.md +26 -15
  2. package/actions/dist/xstate-actions.cjs.dev.js +24 -25
  3. package/actions/dist/xstate-actions.cjs.prod.js +23 -24
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +2 -0
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -0
  7. package/actions/dynamicAction.ts +15 -7
  8. package/actions/package.json +5 -1
  9. package/actors/dist/xstate-actors.cjs.d.ts +1 -1
  10. package/actors/dist/xstate-actors.cjs.dev.js +14 -14
  11. package/actors/dist/xstate-actors.cjs.prod.js +13 -13
  12. package/actors/dist/xstate-actors.esm.js +2 -2
  13. package/actors/dist/xstate-actors.umd.min.js +2 -0
  14. package/actors/dist/xstate-actors.umd.min.js.map +1 -0
  15. package/actors/package.json +5 -1
  16. package/dev/dist/xstate-dev.cjs.dev.js +1 -1
  17. package/dev/dist/xstate-dev.cjs.prod.js +0 -11
  18. package/dev/dist/xstate-dev.esm.js +1 -1
  19. package/dev/dist/xstate-dev.umd.min.js +2 -0
  20. package/dev/dist/xstate-dev.umd.min.js.map +1 -0
  21. package/dev/package.json +5 -1
  22. package/dist/{actions-6b86876d.cjs.dev.js → actions-1e9778c2.cjs.dev.js} +2819 -3334
  23. package/dist/actions-9778f6fb.esm.js +4246 -0
  24. package/dist/actions-acb29ffe.cjs.prod.js +4262 -0
  25. package/dist/declarations/actions/dynamicAction.d.ts +5 -3
  26. package/dist/declarations/src/Machine.d.ts +4 -4
  27. package/dist/declarations/src/Mailbox.d.ts +12 -12
  28. package/dist/declarations/src/SimulatedClock.d.ts +16 -16
  29. package/dist/declarations/src/State.d.ts +97 -104
  30. package/dist/declarations/src/StateMachine.d.ts +110 -112
  31. package/dist/declarations/src/StateNode.d.ts +127 -127
  32. package/dist/declarations/src/actionTypes.d.ts +16 -17
  33. package/dist/declarations/src/actions/assign.d.ts +7 -7
  34. package/dist/declarations/src/actions/cancel.d.ts +10 -10
  35. package/dist/declarations/src/actions/choose.d.ts +3 -3
  36. package/dist/declarations/src/actions/invoke.d.ts +3 -3
  37. package/dist/declarations/src/actions/log.d.ts +11 -11
  38. package/dist/declarations/src/actions/pure.d.ts +3 -3
  39. package/dist/declarations/src/actions/raise.d.ts +8 -9
  40. package/dist/declarations/src/actions/send.d.ts +53 -55
  41. package/dist/declarations/src/actions/stop.d.ts +7 -8
  42. package/dist/declarations/src/actions.d.ts +47 -44
  43. package/dist/declarations/src/actors/callback.d.ts +8 -0
  44. package/dist/declarations/src/actors/index.d.ts +27 -0
  45. package/dist/declarations/src/actors/observable.d.ts +23 -0
  46. package/dist/declarations/src/actors/promise.d.ts +12 -0
  47. package/dist/declarations/src/actors/transition.d.ts +13 -0
  48. package/dist/declarations/src/constants.d.ts +5 -5
  49. package/dist/declarations/src/dev/index.d.ts +14 -14
  50. package/dist/declarations/src/environment.d.ts +1 -1
  51. package/dist/declarations/src/guards.d.ts +8 -9
  52. package/dist/declarations/src/index.d.ts +44 -47
  53. package/dist/declarations/src/interpreter.d.ts +104 -147
  54. package/dist/declarations/src/mapState.d.ts +3 -3
  55. package/dist/declarations/src/memo.d.ts +2 -1
  56. package/dist/declarations/src/schema.d.ts +2 -2
  57. package/dist/declarations/src/spawn.d.ts +2 -2
  58. package/dist/declarations/src/stateUtils.d.ts +70 -85
  59. package/dist/declarations/src/symbolObservable.d.ts +1 -0
  60. package/dist/declarations/src/system.d.ts +2 -0
  61. package/dist/declarations/src/typegenTypes.d.ts +132 -132
  62. package/dist/declarations/src/types.d.ts +1008 -1026
  63. package/dist/declarations/src/utils.d.ts +58 -56
  64. package/dist/{index-20b364c4.esm.js → index-50bd0aff.esm.js} +0 -12
  65. package/dist/{index-2a564d03.cjs.dev.js → index-ebaab3c9.cjs.dev.js} +0 -12
  66. package/dist/xstate.cjs.dev.js +798 -100
  67. package/dist/xstate.cjs.prod.js +797 -99
  68. package/dist/xstate.esm.js +756 -55
  69. package/dist/xstate.umd.min.js +2 -0
  70. package/dist/xstate.umd.min.js.map +1 -0
  71. package/guards/dist/xstate-guards.cjs.dev.js +8 -8
  72. package/guards/dist/xstate-guards.cjs.prod.js +7 -7
  73. package/guards/dist/xstate-guards.esm.js +2 -2
  74. package/guards/dist/xstate-guards.umd.min.js +2 -0
  75. package/guards/dist/xstate-guards.umd.min.js.map +1 -0
  76. package/guards/package.json +5 -1
  77. package/package.json +28 -6
  78. package/CHANGELOG.md +0 -1986
  79. package/actions/ExecutableAction.ts +0 -58
  80. package/dist/Machine-9ce74c11.cjs.dev.js +0 -755
  81. package/dist/Machine-dca041dc.cjs.prod.js +0 -749
  82. package/dist/Machine-fb2f47f5.esm.js +0 -751
  83. package/dist/actions-70094c93.cjs.prod.js +0 -4765
  84. package/dist/actions-ff512f16.esm.js +0 -4757
  85. package/dist/declarations/actions/ExecutableAction.d.ts +0 -23
  86. package/dist/declarations/src/ObservableActorRef.d.ts +0 -25
  87. package/dist/declarations/src/actors.d.ts +0 -38
  88. package/dist/declarations/src/match.d.ts +0 -5
  89. package/dist/declarations/src/model.d.ts +0 -5
  90. package/dist/declarations/src/model.types.d.ts +0 -53
  91. package/dist/declarations/src/registry.d.ts +0 -8
  92. package/model/dist/xstate-model.cjs.d.ts +0 -1
  93. package/model/dist/xstate-model.cjs.dev.js +0 -41
  94. package/model/dist/xstate-model.cjs.js +0 -7
  95. package/model/dist/xstate-model.cjs.prod.js +0 -41
  96. package/model/dist/xstate-model.esm.js +0 -37
  97. package/model/package.json +0 -4
package/CHANGELOG.md DELETED
@@ -1,1986 +0,0 @@
1
- # xstate
2
-
3
- ## 5.0.0-alpha.0
4
-
5
- ### Major Changes
6
-
7
- - [#1045](https://github.com/statelyai/xstate/pull/1045) [`7f3b84816`](https://github.com/statelyai/xstate/commit/7f3b84816564d951b6b29afdd7075256f1f59501) Thanks [@davidkpiano](https://github.com/davidkpiano)! - - The third argument of `machine.transition(state, event)` has been removed. The `context` should always be given as part of the `state`.
8
-
9
- - There is a new method: `machine.microstep(state, event)` which returns the resulting intermediate `State` object that represents a single microstep being taken when transitioning from `state` via the `event`. This is the `State` that does not take into account transient transitions nor raised events, and is useful for debugging.
10
-
11
- - The `state.events` property has been removed from the `State` object, and is replaced internally by `state._internalQueue`, which represents raised events to be processed in a macrostep loop. The `state._internalQueue` property should be considered internal (not used in normal development).
12
-
13
- - The `state.historyValue` property now more closely represents the original SCXML algorithm, and is a mapping of state node IDs to their historic descendent state nodes. This is used for resolving history states, and should be considered internal.
14
-
15
- - The `stateNode.isTransient` property is removed from `StateNode`.
16
-
17
- - The `.initial` property of a state node config object can now contain executable content (i.e., actions):
18
-
19
- ```js
20
- // ...
21
- initial: {
22
- target: 'someTarget',
23
- actions: [/* initial actions */]
24
- }
25
- ```
26
-
27
- - Assign actions (via `assign()`) will now be executed "in order", rather than automatically prioritized. They will be evaluated after previously defined actions are evaluated, and actions that read from `context` will have those intermediate values applied, rather than the final resolved value of all `assign()` actions taken, which was the previous behavior.
28
-
29
- This shouldn't change the behavior for most state machines. To maintain the previous behavior, ensure that `assign()` actions are defined before any other actions.
30
-
31
- * [#1669](https://github.com/statelyai/xstate/pull/1669) [`969a2f4fc`](https://github.com/statelyai/xstate/commit/969a2f4fc0bc9147b9a52da25306e5c13b97f159) Thanks [@davidkpiano](https://github.com/davidkpiano)! - An error will be thrown if an `initial` state key is not specified for compound state nodes. For example:
32
-
33
- ```js
34
- const lightMachine = createMachine({
35
- id: 'light',
36
- initial: 'green',
37
- states: {
38
- green: {},
39
- yellow: {},
40
- red: {
41
- // Forgotten initial state:
42
- // initial: 'walk',
43
- states: {
44
- walk: {},
45
- wait: {}
46
- }
47
- }
48
- }
49
- });
50
- ```
51
-
52
- You will get the error:
53
-
54
- ```
55
- No initial state specified for state node "#light.red". Try adding { initial: "walk" } to the state config.
56
- ```
57
-
58
- - [#2294](https://github.com/statelyai/xstate/pull/2294) [`c0a6dcafa`](https://github.com/statelyai/xstate/commit/c0a6dcafa1a11a5ff1660b57e0728675f155c292) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The machine's `context` is now restricted to an `object`. This was the most common usage, but now the typings prevent `context` from being anything but an object:
59
-
60
- ```ts
61
- const machine = createMachine({
62
- // This will produce the TS error:
63
- // "Type 'string' is not assignable to type 'object | undefined'"
64
- context: 'some string'
65
- });
66
- ```
67
-
68
- If `context` is `undefined`, it will now default to an empty object `{}`:
69
-
70
- ```ts
71
- const machine = createMachine({
72
- // No context
73
- });
74
-
75
- machine.initialState.context;
76
- // => {}
77
- ```
78
-
79
- * [#1260](https://github.com/statelyai/xstate/pull/1260) [`172d6a7e1`](https://github.com/statelyai/xstate/commit/172d6a7e1e4ab0fa73485f76c52675be8a1f3362) Thanks [@davidkpiano](https://github.com/davidkpiano)! - All generic types containing `TContext` and `TEvent` will now follow the same, consistent order:
80
-
81
- 1. `TContext`
82
- 2. `TEvent`
83
- 3. ... All other generic types, including `TStateSchema,`TTypestate`, etc.
84
-
85
- ```diff
86
- -const service = interpret<SomeCtx, SomeSchema, SomeEvent>(someMachine);
87
- +const service = interpret<SomeCtx, SomeEvent, SomeSchema>(someMachine);
88
- ```
89
-
90
- - [#1808](https://github.com/statelyai/xstate/pull/1808) [`31bc73e05`](https://github.com/statelyai/xstate/commit/31bc73e05692f29301f5bb5cb4b87b90773e0ef2) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Renamed `machine.withConfig(...)` to `machine.provide(...)`.
91
-
92
- * [#878](https://github.com/statelyai/xstate/pull/878) [`e09efc720`](https://github.com/statelyai/xstate/commit/e09efc720f05246b692d0fdf17cf5d8ac0344ee6) Thanks [@Andarist](https://github.com/Andarist)! - Removed third parameter (context) from Machine's transition method. If you want to transition with a particular context value you should create appropriate `State` using `State.from`. So instead of this - `machine.transition('green', 'TIMER', { elapsed: 100 })`, you should do this - `machine.transition(State.from('green', { elapsed: 100 }), 'TIMER')`.
93
-
94
- - [#1203](https://github.com/statelyai/xstate/pull/1203) [`145539c4c`](https://github.com/statelyai/xstate/commit/145539c4cfe1bde5aac247792622428e44342dd6) Thanks [@davidkpiano](https://github.com/davidkpiano)! - - The `execute` option for an interpreted service has been removed. If you don't want to execute actions, it's recommended that you don't hardcode implementation details into the base `machine` that will be interpreted, and extend the machine's `options.actions` instead. By default, the interpreter will execute all actions according to SCXML semantics (immediately upon transition).
95
-
96
- - Dev tools integration has been simplified, and Redux dev tools support is no longer the default. It can be included from `xstate/devTools/redux`:
97
-
98
- ```js
99
- import { interpret } from 'xstate';
100
- import { createReduxDevTools } from 'xstate/devTools/redux';
101
-
102
- const service = interpret(someMachine, {
103
- devTools: createReduxDevTools({
104
- // Redux Dev Tools options
105
- })
106
- });
107
- ```
108
-
109
- By default, dev tools are attached to the global `window.__xstate__` object:
110
-
111
- ```js
112
- const service = interpret(someMachine, {
113
- devTools: true // attaches via window.__xstate__.register(service)
114
- });
115
- ```
116
-
117
- And creating your own custom dev tools adapter is a function that takes in the `service`:
118
-
119
- ```js
120
- const myCustomDevTools = service => {
121
- console.log('Got a service!');
122
-
123
- service.subscribe(state => {
124
- // ...
125
- });
126
- };
127
-
128
- const service = interpret(someMachine, {
129
- devTools: myCustomDevTools
130
- });
131
- ```
132
-
133
- - These handlers have been removed, as they are redundant and can all be accomplished with `.onTransition(...)` and/or `.subscribe(...)`:
134
-
135
- - `service.onEvent()`
136
- - `service.onSend()`
137
- - `service.onChange()`
138
-
139
- - The `service.send(...)` method no longer returns the next state. It is a `void` function (fire-and-forget).
140
-
141
- - The `service.sender(...)` method has been removed as redundant. Use `service.send(...)` instead.
142
-
143
- * [#953](https://github.com/statelyai/xstate/pull/953) [`3de36bb24`](https://github.com/statelyai/xstate/commit/3de36bb24e8f59f54d571bf587407b1b6a9856e0) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Support for getters as a transition target (instead of referencing state nodes by ID or relative key) has been removed.
144
-
145
- The `Machine()` and `createMachine()` factory functions no longer support passing in `context` as a third argument.
146
-
147
- The `context` property in the machine configuration no longer accepts a function for determining context (which was introduced in 4.7). This might change as the API becomes finalized.
148
-
149
- The `activities` property was removed from `State` objects, as activities are now part of `invoke` declarations.
150
-
151
- The state nodes will not show the machine's `version` on them - the `version` property is only available on the root machine node.
152
-
153
- The `machine.withContext({...})` method now permits providing partial context, instead of the entire machine context.
154
-
155
- - [#1443](https://github.com/statelyai/xstate/pull/1443) [`9e10660ec`](https://github.com/statelyai/xstate/commit/9e10660ec2f1e89cbb09a1094edb4f6b8a273a99) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `in: ...` property for transitions is removed and replaced with guards. It is recommended to use `stateIn()` and `not(stateIn())` guard creators instead:
156
-
157
- ```diff
158
- + import { stateIn } from 'xstate/guards';
159
-
160
- // ...
161
- on: {
162
- SOME_EVENT: {
163
- target: 'somewhere',
164
- - in: '#someState'
165
- + cond: stateIn('#someState')
166
- }
167
- }
168
- // ...
169
- ```
170
-
171
- * [#1456](https://github.com/statelyai/xstate/pull/1456) [`8fcbddd51`](https://github.com/statelyai/xstate/commit/8fcbddd51d66716ab1d326d934566a7664a4e175) Thanks [@davidkpiano](https://github.com/davidkpiano)! - There is now support for higher-level guards, which are guards that can compose other guards:
172
-
173
- - `and([guard1, guard2, /* ... */])` returns `true` if _all_ guards evaluate to truthy, otherwise `false`
174
- - `or([guard1, guard2, /* ... */])` returns `true` if _any_ guard evaluates to truthy, otherwise `false`
175
- - `not(guard1)` returns `true` if a single guard evaluates to `false`, otherwise `true`
176
-
177
- ```js
178
- import { and, or, not } from 'xstate/guards';
179
-
180
- const someMachine = createMachine({
181
- // ...
182
- on: {
183
- EVENT: {
184
- target: 'somewhere',
185
- guard: and([
186
- 'stringGuard',
187
- or([{ type: 'anotherGuard' }, not(() => false)])
188
- ])
189
- }
190
- }
191
- });
192
- ```
193
-
194
- - [#2824](https://github.com/statelyai/xstate/pull/2824) [`515cdc9c1`](https://github.com/statelyai/xstate/commit/515cdc9c148a3a1b558120c309080e9a21e876bc) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Actions and guards that follow eventless transitions will now receive the event that triggered the transition instead of a "null" event (`{ type: '' }`), which no longer exists:
195
-
196
- ```js
197
- // ...
198
- states: {
199
- a: {
200
- on: {
201
- SOME_EVENT: 'b'
202
- }
203
- },
204
- b: {
205
- always: 'c'
206
- },
207
- c: {
208
- entry: [(_, event) => {
209
- // event.type is now "SOME_EVENT", not ""
210
- }]
211
- }
212
- }
213
- // ...
214
- ```
215
-
216
- * [#1240](https://github.com/statelyai/xstate/pull/1240) [`6043a1c28`](https://github.com/statelyai/xstate/commit/6043a1c28d21ff8cbabc420a6817a02a1a54fcc8) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `in: '...'` transition property can now be replaced with `stateIn(...)` and `stateNotIn(...)` guards, imported from `xstate/guards`:
217
-
218
- ```diff
219
- import {
220
- createMachine,
221
- + stateIn
222
- } from 'xstate/guards';
223
-
224
- const machine = createMachine({
225
- // ...
226
- on: {
227
- SOME_EVENT: {
228
- target: 'anotherState',
229
- - in: '#someState',
230
- + cond: stateIn('#someState')
231
- }
232
- }
233
- })
234
- ```
235
-
236
- The `stateIn(...)` and `stateNotIn(...)` guards also can be used the same way as `state.matches(...)`:
237
-
238
- ```js
239
- // ...
240
- SOME_EVENT: {
241
- target: 'anotherState',
242
- cond: stateNotIn({ red: 'stop' })
243
- }
244
- ```
245
-
246
- ---
247
-
248
- An error will now be thrown if the `assign(...)` action is executed when the `context` is `undefined`. Previously, there was only a warning.
249
-
250
- ---
251
-
252
- The SCXML event `error.execution` will be raised if assignment in an `assign(...)` action fails.
253
-
254
- ---
255
-
256
- Error events raised by the machine will be _thrown_ if there are no error listeners registered on a service via `service.onError(...)`.
257
-
258
- - [#2824](https://github.com/statelyai/xstate/pull/2824) [`6a6b2b869`](https://github.com/statelyai/xstate/commit/6a6b2b8691626112d1d9dbf23d0a0e80ff7130a8) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Eventless transitions must now be specified in the `always: { ... }` object and not in the `on: { ... }` object:
259
-
260
- ```diff
261
- someState: {
262
- on: {
263
- // Will no longer work
264
- - '': { target: 'anotherState' }
265
- },
266
- + always: { target: 'anotherState' }
267
- }
268
- ```
269
-
270
- * [#2484](https://github.com/statelyai/xstate/pull/2484) [`0b49437b1`](https://github.com/statelyai/xstate/commit/0b49437b1be3e6d9bc61304711b83300cba88dc4) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Parameterized actions now require a `params` property:
271
-
272
- ```diff
273
- // ...
274
- entry: [
275
- {
276
- type: 'greet',
277
- - message: 'Hello'
278
- + params: { message: 'Hello' }
279
- }
280
- ]
281
- // ...
282
- ```
283
-
284
- - [#987](https://github.com/statelyai/xstate/pull/987) [`0e24ea6d6`](https://github.com/statelyai/xstate/commit/0e24ea6d62a5c1a8b7e365f2252dc930d94997c4) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `internal` property will no longer have effect for transitions on atomic (leaf-node) state nodes. In SCXML, `internal` only applies to complex (compound and parallel) state nodes:
285
-
286
- > Determines whether the source state is exited in transitions whose target state is a descendant of the source state. [See 3.13 Selecting and Executing Transitions for details.](https://www.w3.org/TR/scxml/#SelectingTransitions)
287
-
288
- ```diff
289
- // ...
290
- green: {
291
- on: {
292
- NOTHING: {
293
- - target: 'green',
294
- - internal: true,
295
- actions: doSomething
296
- }
297
- }
298
- }
299
- ```
300
-
301
- * [#987](https://github.com/statelyai/xstate/pull/987) [`04e89f90f`](https://github.com/statelyai/xstate/commit/04e89f90f97fe25a45b5908c45f25a513f0fd70f) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The history resolution algorithm has been refactored to closely match the SCXML algorithm, which changes the shape of `state.historyValue` to map history state node IDs to their most recently resolved target state nodes.
302
-
303
- - [#2882](https://github.com/statelyai/xstate/pull/2882) [`0096d9f7a`](https://github.com/statelyai/xstate/commit/0096d9f7afda7546fc7b1d5fdd1546f55c32bfe4) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `state.history` property has been removed. This does not affect the machine "history" mechanism.
304
-
305
- Storing previous state should now be done explicitly:
306
-
307
- ```js
308
- let previousState;
309
-
310
- const service = interpret(someMachine)
311
- .onTransition(state => {
312
- // previousState represents the last state here
313
-
314
- // ...
315
-
316
- // update the previous state at the end
317
- previousState = state;
318
- })
319
- .start();
320
- ```
321
-
322
- * [#1456](https://github.com/statelyai/xstate/pull/1456) [`8fcbddd51`](https://github.com/statelyai/xstate/commit/8fcbddd51d66716ab1d326d934566a7664a4e175) Thanks [@davidkpiano](https://github.com/davidkpiano)! - BREAKING: The `cond` property in transition config objects has been renamed to `guard`. This unifies terminology for guarded transitions and guard predicates (previously called "cond", or "conditional", predicates):
323
-
324
- ```diff
325
- someState: {
326
- on: {
327
- EVENT: {
328
- target: 'anotherState',
329
- - cond: 'isValid'
330
- + guard: 'isValid'
331
- }
332
- }
333
- }
334
- ```
335
-
336
- - [#2060](https://github.com/statelyai/xstate/pull/2060) [`b200e0e0b`](https://github.com/statelyai/xstate/commit/b200e0e0b7123797086080b75abdfcf2fce45253) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `Machine()` function has been removed. Use the `createMachine()` function instead.
337
-
338
- ```diff
339
- -import { Machine } from 'xstate';
340
- +import { createMachine } from 'xstate';
341
-
342
- -const machine = Machine({
343
- +const machine = createMachine({
344
- // ...
345
- });
346
- ```
347
-
348
- * [#3148](https://github.com/statelyai/xstate/pull/3148) [`7a68cbb61`](https://github.com/statelyai/xstate/commit/7a68cbb615afb6556c83868535dae67af366a117) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `spawn` is no longer importable from `xstate`. Instead you get it in `assign` like this:
349
-
350
- ```js
351
- assign((ctx, ev, { spawn }) => {
352
- return {
353
- ...ctx,
354
- actorRef: spawn(promiseActor)
355
- };
356
- });
357
- ```
358
-
359
- In addition to that, you can now `spawn` actors defined in your implementations object, in the same way that you were already able to do that with `invoke`. To do that just reference the defined actor like this:
360
-
361
- ```js
362
- spawn('promiseActor');
363
- ```
364
-
365
- - [#2869](https://github.com/statelyai/xstate/pull/2869) [`9437c3de9`](https://github.com/statelyai/xstate/commit/9437c3de912c2a38c04798cbb94f267a1e5db3f8) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `service.batch(events)` method is no longer available.
366
-
367
- * [#2191](https://github.com/statelyai/xstate/pull/2191) [`0038c7b1e`](https://github.com/statelyai/xstate/commit/0038c7b1e2050fe7262849aab8fdff4a7ce7cf92) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `StateSchema` type has been removed from all generic type signatures.
368
-
369
- - [#3148](https://github.com/statelyai/xstate/pull/3148) [`7a68cbb61`](https://github.com/statelyai/xstate/commit/7a68cbb615afb6556c83868535dae67af366a117) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `EmittedFrom` type helper has been renamed to `SnapshotFrom`.
370
-
371
- * [#1163](https://github.com/statelyai/xstate/pull/1163) [`390eaaa52`](https://github.com/statelyai/xstate/commit/390eaaa523cb0dd243e39c6300e671606c1e45fc) Thanks [@davidkpiano](https://github.com/davidkpiano)! - **Breaking:** The `state.children` property is now a mapping of invoked actor IDs to their `ActorRef` instances.
372
-
373
- **Breaking:** The way that you interface with invoked/spawned actors is now through `ActorRef` instances. An `ActorRef` is an opaque reference to an `Actor`, which should be never referenced directly.
374
-
375
- **Breaking:** The `origin` of an `SCXML.Event` is no longer a string, but an `ActorRef` instance.
376
-
377
- - [#3148](https://github.com/statelyai/xstate/pull/3148) [`7a68cbb61`](https://github.com/statelyai/xstate/commit/7a68cbb615afb6556c83868535dae67af366a117) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `services` option passed as the second argument to `createMachine(config, options)` is renamed to `actors`. Each value in `actors` should be a function that takes in `context` and `event` and returns a [behavior](TODO: link) for an actor. The provided behavior creators are:
378
-
379
- - `fromMachine`
380
- - `fromPromise`
381
- - `fromCallback`
382
- - `fromObservable`
383
- - `fromEventObservable`
384
-
385
- ```diff
386
- import { createMachine } from 'xstate';
387
- +import { fromPromise } from 'xstate/actors';
388
-
389
- const machine = createMachine(
390
- {
391
- // ...
392
- invoke: {
393
- src: 'fetchFromAPI'
394
- }
395
- },
396
- {
397
- - services: {
398
- + actors: {
399
- - fetchFromAPI: (context, event) => {
400
- + fetchFromAPI: (context, event) => fromPromise(() => {
401
- // ... (return a promise)
402
- })
403
- }
404
- }
405
- );
406
- ```
407
-
408
- * [#878](https://github.com/statelyai/xstate/pull/878) [`e09efc720`](https://github.com/statelyai/xstate/commit/e09efc720f05246b692d0fdf17cf5d8ac0344ee6) Thanks [@Andarist](https://github.com/Andarist)! - Support for compound string state values has been dropped from Machine's transition method. It's no longer allowed to call transition like this - `machine.transition('a.b', 'NEXT')`, instead it's required to use "state value" representation like this - `machine.transition({ a: 'b' }, 'NEXT')`.
409
-
410
- - [#898](https://github.com/statelyai/xstate/pull/898) [`025a2d6a2`](https://github.com/statelyai/xstate/commit/025a2d6a295359a746bee6ffc2953ccc51a6aaad) Thanks [@davidkpiano](https://github.com/davidkpiano)! - - Breaking: activities removed (can be invoked)
411
-
412
- Since activities can be considered invoked services, they can be implemented as such. Activities are services that do not send any events back to the parent machine, nor do they receive any events, other than a "stop" signal when the parent changes to a state where the activity is no longer active. This is modeled the same way as a callback service is modeled.
413
-
414
- * [#878](https://github.com/statelyai/xstate/pull/878) [`e09efc720`](https://github.com/statelyai/xstate/commit/e09efc720f05246b692d0fdf17cf5d8ac0344ee6) Thanks [@Andarist](https://github.com/Andarist)! - Removed previously deprecated config properties: `onEntry`, `onExit`, `parallel` and `forward`.
415
-
416
- - [#2876](https://github.com/statelyai/xstate/pull/2876) [`c99bb43af`](https://github.com/statelyai/xstate/commit/c99bb43afec01ddee86fc746c346ea1aeeca687d) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Typings for `Typestate` have been removed. The reason for this is that types for typestates needed to be manually specified, which is unsound because it is possible to specify _impossible_ typestates; i.e., typings for a state's `value` and `context` that are impossible to achieve.
417
-
418
- * [#2840](https://github.com/statelyai/xstate/pull/2840) [`fc5ca7b7f`](https://github.com/statelyai/xstate/commit/fc5ca7b7fcd2d7821ce2409743c50505529104e7) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Invoked/spawned actors are no longer available on `service.children` - they can only be accessed from `state.children`.
419
-
420
- - [#1811](https://github.com/statelyai/xstate/pull/1811) [`5d16a7365`](https://github.com/statelyai/xstate/commit/5d16a73651e97dd0228c5215cb2452a4d9951118) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Prefix wildcard event descriptors are now supported. These are event descriptors ending with `".*"` which will match all events that start with the prefix (the partial event type before `".*"`):
421
-
422
- ```js
423
- // ...
424
- on: {
425
- 'mouse.click': {/* ... */},
426
- // Matches events such as:
427
- // "pointer.move"
428
- // "pointer.move.out"
429
- // "pointer"
430
- 'pointer.*': {/* ... */}
431
- }
432
- // ...
433
- ```
434
-
435
- Note: wildcards are only valid as the entire event type (`"*"`) or at the end of an event type, preceded by a period (`".*"`):
436
-
437
- - ✅ `"*"`
438
- - ✅ `"event.*"`
439
- - ✅ `"event.something.*"`
440
- - ❌ ~`"event.*.something"`~
441
- - ❌ ~`"event*"`~
442
- - ❌ ~`"event*.some*thing"`~
443
- - ❌ ~`"*.something"`~
444
-
445
- * [#1456](https://github.com/statelyai/xstate/pull/1456) [`8fcbddd51`](https://github.com/statelyai/xstate/commit/8fcbddd51d66716ab1d326d934566a7664a4e175) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The interface for guard objects has changed. Notably, all guard parameters should be placed in the `params` property of the guard object:
446
-
447
- Example taken from [Custom Guards](https://xstate.js.org/docs/guides/guards.html#custom-guards):
448
-
449
- ```diff
450
- -cond: {
451
- +guard: {
452
- - name: 'searchValid', // `name` property no longer used
453
- type: 'searchValid',
454
- - minQueryLength: 3
455
- + params: {
456
- + minQueryLength: 3
457
- + }
458
- }
459
- ```
460
-
461
- - [#1054](https://github.com/statelyai/xstate/pull/1054) [`53a594e9a`](https://github.com/statelyai/xstate/commit/53a594e9a1b49ccb1121048a5784676f83950024) Thanks [@Andarist](https://github.com/Andarist)! - `Machine#transition` no longer handles invalid state values such as values containing non-existent state regions. If you rehydrate your machines and change machine's schema then you should migrate your data accordingly on your own.
462
-
463
- * [#1002](https://github.com/statelyai/xstate/pull/1002) [`31a0d890f`](https://github.com/statelyai/xstate/commit/31a0d890f55d8f0b06772c9fd510b18302b76ebb) Thanks [@Andarist](https://github.com/Andarist)! - Removed support for `service.send(type, payload)`. We are using `send` API at multiple places and this was the only one supporting this shape of parameters. Additionally, it had not strict TS types and using it was unsafe (type-wise).
464
-
465
- ### Minor Changes
466
-
467
- - [#3148](https://github.com/statelyai/xstate/pull/3148) [`7a68cbb61`](https://github.com/statelyai/xstate/commit/7a68cbb615afb6556c83868535dae67af366a117) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `onSnapshot` is now available for invoke configs. You can specify a transition there to be taken when a snapshot of an invoked actor gets updated. It works similarly to `onDone`/`onError`.
468
-
469
- * [#1041](https://github.com/statelyai/xstate/pull/1041) [`b24e47b9e`](https://github.com/statelyai/xstate/commit/b24e47b9e7a59a5b0527d4386cea3af16c84ca7a) Thanks [@Andarist](https://github.com/Andarist)! - Support for specifying states deep in the hierarchy has been added for the `initial` property. It's also now possible to specify multiple states as initial ones - so you can enter multiple descandants which have to be **parallel** to each other. Keep also in mind that you can only target descendant states with the `initial` property - it's not possible to target states from another regions.
470
-
471
- Those are now possible:
472
-
473
- ```js
474
- {
475
- initial: '#some_id',
476
- initial: ['#some_id', '#another_id'],
477
- initial: { target: '#some_id' },
478
- initial: { target: ['#some_id', '#another_id'] },
479
- }
480
- ```
481
-
482
- - [#1028](https://github.com/statelyai/xstate/pull/1028) [`0c6cfee9a`](https://github.com/statelyai/xstate/commit/0c6cfee9a6d603aa1756e3a6d0f76d4da1486caf) Thanks [@Andarist](https://github.com/Andarist)! - Added support for expressions to `cancel` action.
483
-
484
- * [#898](https://github.com/statelyai/xstate/pull/898) [`c9cda27cb`](https://github.com/statelyai/xstate/commit/c9cda27cbe52b9c706ccb63b709d22d049be31e3) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Added interop observable symbols to `ActorRef` so that actor refs are compatible with libraries like RxJS.
485
-
486
- ## 4.32.1
487
-
488
- ### Patch Changes
489
-
490
- - [#3292](https://github.com/statelyai/xstate/pull/3292) [`16514e466`](https://github.com/statelyai/xstate/commit/16514e4663deba95731a84deaee94c17edec1e06) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue in the `EmittedFrom` type helper that could prevent it from inferring the desired type from some services.
491
-
492
- ## 4.32.0
493
-
494
- ### Minor Changes
495
-
496
- - [#3234](https://github.com/statelyai/xstate/pull/3234) [`ce376b388`](https://github.com/statelyai/xstate/commit/ce376b3889ea900e67d20026517b87185377c32e) Thanks [@Andarist](https://github.com/Andarist)! - Added a `StateValueFrom` helper that can be used to extract valid state values from a machine. This might specifically be useful with typegen because typegenless `state.matches` accepts `any` anyway.
497
-
498
- ### Patch Changes
499
-
500
- - [#3215](https://github.com/statelyai/xstate/pull/3215) [`44c66e74f`](https://github.com/statelyai/xstate/commit/44c66e74f9eafbb326979234e2bbe51e38dc3a86) Thanks [@tom-sherman](https://github.com/tom-sherman)! - Removing the timeout that's built in to `waitFor` is now supported by explicitly passing an `Infinity` value.
501
-
502
- Example usage:
503
-
504
- ```js
505
- import { waitFor } from 'xstate/lib/waitFor';
506
-
507
- // This will
508
- const loggedInState = await waitFor(
509
- loginService,
510
- state => state.hasTag('loggedIn'),
511
- { timeout: Infinity }
512
- );
513
- ```
514
-
515
- This fixes a bug that causes `waitFor` to reject with an error immediately due to the behaviour of `setTimeout`.
516
-
517
- * [#3230](https://github.com/statelyai/xstate/pull/3230) [`780458c92`](https://github.com/statelyai/xstate/commit/780458c921d4525c7a00119c7eb43d4833978861) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with typegen types not being able to provide events that had a union of strings as their `type` (such as `{ type: 'INC' | 'DEC'; value: number; }`).
518
-
519
- - [#3252](https://github.com/statelyai/xstate/pull/3252) [`a94dfd467`](https://github.com/statelyai/xstate/commit/a94dfd46772cacc59154c165f27122164f48625b) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `EventFrom` not being able to extract events that had a union of strings as their `type` (such as `{ type: 'INC' | 'DEC'; value: number; }`).
520
-
521
- * [#3090](https://github.com/statelyai/xstate/pull/3090) [`c4f73ca13`](https://github.com/statelyai/xstate/commit/c4f73ca1356d106423c8b4ee34865f7e4f2d2bb6) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with action objects not receiving correct event types when used in the second argument to the `createMachine`.
522
-
523
- - [#3238](https://github.com/statelyai/xstate/pull/3238) [`3df6335ef`](https://github.com/statelyai/xstate/commit/3df6335ef8db4edcf0a47d4c559716552ce4bbe8) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The typings for `sendTo(...)` have been fixed.
524
-
525
- * [#3228](https://github.com/statelyai/xstate/pull/3228) [`fe5f0e6c9`](https://github.com/statelyai/xstate/commit/fe5f0e6c9bbb6ff740673889892301c8989eacfd) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with inline functions in the config object used as transition actions not having their argument types inferred.
526
-
527
- - [#3252](https://github.com/statelyai/xstate/pull/3252) [`a94dfd467`](https://github.com/statelyai/xstate/commit/a94dfd46772cacc59154c165f27122164f48625b) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with default `TEvent` (`{ type: string }`) not being correctly provided to inline transition actions.
528
-
529
- ## 4.31.0
530
-
531
- ### Minor Changes
532
-
533
- - [#3190](https://github.com/statelyai/xstate/pull/3190) [`fbf5ca0ad`](https://github.com/statelyai/xstate/commit/fbf5ca0adcafacbf170f5522eec64ac612bdeb47) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `waitFor(...)` helper function, which asynchronously _waits_ for an actor's emitted value to satisfy a `predicate` before a `timeout`, is now available.
534
-
535
- Example usage:
536
-
537
- ```js
538
- import { waitFor } from 'xstate/lib/waitFor';
539
-
540
- // ...
541
- const loginService = interpret(loginMachine).start();
542
-
543
- const loggedInState = await waitFor(loginService, state =>
544
- state.hasTag('loggedIn')
545
- );
546
-
547
- loggedInState.hasTag('loggedIn'); // true
548
- ```
549
-
550
- * [#3200](https://github.com/statelyai/xstate/pull/3200) [`56c0a36`](https://github.com/statelyai/xstate/commit/56c0a36f222195d0b18edd7a72d5429a213b3808) Thanks [@Andarist](https://github.com/Andarist)! - Subscribing to a stopped interpreter will now always immediately emit its state and call a completion callback.
551
-
552
- ### Patch Changes
553
-
554
- - [#3166](https://github.com/statelyai/xstate/pull/3166) [`be4c5c74d`](https://github.com/statelyai/xstate/commit/be4c5c74d400a1ca58befd306029c3ce77793e3e) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `state.tags` not having correct values when resolving micro transitions (taken in response to raised events). This was creating issues when checking tags in guards.
555
-
556
- * [#3171](https://github.com/statelyai/xstate/pull/3171) [`14f8b4785`](https://github.com/statelyai/xstate/commit/14f8b4785599fb366ae2901c03c2a3202594499c) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `onDone` on parallel states not being "called" correctly when a parallel state had a history state defined directly on it.
557
-
558
- - [#2939](https://github.com/statelyai/xstate/pull/2939) [`360e85462`](https://github.com/statelyai/xstate/commit/360e8546298c4a06b6d51d8f12c0563672dd7acf) Thanks [@Andarist](https://github.com/Andarist)! - Fixed issues with not disposing some cached internal values when stopping interpreters, which could have led to issues when starting such an interpreter again.
559
-
560
- * [#3153](https://github.com/statelyai/xstate/pull/3153) [`b36ef9dda`](https://github.com/statelyai/xstate/commit/b36ef9dda560fca4c00428f48742fd9d2e325324) Thanks [@Andarist](https://github.com/Andarist)! - Made type displays (like in the IDE tooltips etc) more readable by using a type interface for the internal `ResolveTypegenMeta` type.
561
-
562
- ## 4.30.6
563
-
564
- ### Patch Changes
565
-
566
- - [#3131](https://github.com/statelyai/xstate/pull/3131) [`d9a0bcfc9`](https://github.com/statelyai/xstate/commit/d9a0bcfc9be03e49726d6dc4a6bbce25239913a1) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with event type being inferred from too many places within `createMachine` call and possibly ending up as `any`/`AnyEventObject` for the entire machine.
567
-
568
- * [#3133](https://github.com/statelyai/xstate/pull/3133) [`4feef9d47`](https://github.com/statelyai/xstate/commit/4feef9d47f81d1b28f2f898431eb4bd1c42d8368) Thanks [@fw6](https://github.com/fw6)! - Fixed compatibility with esoteric [Mini Program](https://developers.weixin.qq.com/miniprogram/en/dev/framework/app-service/) environment where `global` object was available but `global.console` wasn't.
569
-
570
- - [#3140](https://github.com/statelyai/xstate/pull/3140) [`502ffe91a`](https://github.com/statelyai/xstate/commit/502ffe91a19579f5f747b76ce29d50de81e8b15c) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with interpreters started using a persisted state not being "resolved" in full. This could cause some things, such as `after` transitions, not being executed correctly after starting an interpreter like this.
571
-
572
- * [#3147](https://github.com/statelyai/xstate/pull/3147) [`155539c85`](https://github.com/statelyai/xstate/commit/155539c8597b2f2783e8419c782922545d7e6424) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a TS inference issue causing some functions to infer the constraint type for the event type even though a `StateMachine` passed to the function was parametrized with a concrete type for the event. More information can be found [here](https://github.com/statelyai/xstate/issues/3141#issuecomment-1063995705).
573
-
574
- - [#3146](https://github.com/statelyai/xstate/pull/3146) [`4cf89b5f9`](https://github.com/statelyai/xstate/commit/4cf89b5f9cf645f741164d23e3bc35dd7c5706f6) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility of `Interpreter` with older versions of TypeScript. This ensures that our interpreters can correctly be consumed by functions expecting `ActorRef` interface (like for example `useSelector`).
575
-
576
- * [#3139](https://github.com/statelyai/xstate/pull/3139) [`7b45fda9e`](https://github.com/statelyai/xstate/commit/7b45fda9e1bd544b505c86ddcd6cf1f949007fef) Thanks [@Andarist](https://github.com/Andarist)! - `InterpreterFrom` and `ActorRefFrom` types used on machines with typegen data should now correctly return types with final/resolved typegen data. The "final" type here means a type that already encodes the information that all required implementations have been provided. Before this change this wouldn't typecheck correctly:
577
-
578
- ```ts
579
- const machine = createMachine({
580
- // this encodes that we still expect `myAction` to be provided
581
- tsTypes: {} as Typegen0
582
- });
583
- const service: InterpreterFrom<typeof machine> = machine.withConfig({
584
- actions: {
585
- myAction: () => {}
586
- }
587
- });
588
- ```
589
-
590
- - [#3097](https://github.com/statelyai/xstate/pull/3097) [`c881c8ca9`](https://github.com/statelyai/xstate/commit/c881c8ca9baaf4928064a04d7034cd775a702bc2) Thanks [@davidkpiano](https://github.com/davidkpiano)! - State that is persisted and restored from `machine.resolveState(state)` will now have the correct `state.machine` value, so that `state.can(...)` and other methods will work as expected. See [#3096](https://github.com/statelyai/xstate/issues/3096) for more details.
591
-
592
- ## 4.30.5
593
-
594
- ### Patch Changes
595
-
596
- - [#3118](https://github.com/statelyai/xstate/pull/3118) [`28e353081`](https://github.com/statelyai/xstate/commit/28e3530818e1d800eba7b6d821bde0c0048f0579) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a bundling issue that prevented the `keys()` export to be preserved in the previous release.
597
-
598
- ## 4.30.4
599
-
600
- ### Patch Changes
601
-
602
- - [#3104](https://github.com/statelyai/xstate/pull/3104) [`3706c62f4`](https://github.com/statelyai/xstate/commit/3706c62f49daa5cf84172713a004eb26704342f5) Thanks [@Andarist](https://github.com/Andarist)! - Fixed `ContextFrom` helper type to work on typegened machines.
603
-
604
- * [#3113](https://github.com/statelyai/xstate/pull/3113) [`144131bed`](https://github.com/statelyai/xstate/commit/144131beda5c00a15fbe0f58a3309eac81d940eb) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `keys()` utility function export, which was removed in [#3089](https://github.com/statelyai/xstate/issues/3089), is now added back, as older versions of XState libraries may depend on it still. See [#3106](https://github.com/statelyai/xstate/issues/3106) for more details.
605
-
606
- - [#3104](https://github.com/statelyai/xstate/pull/3104) [`3706c62f4`](https://github.com/statelyai/xstate/commit/3706c62f49daa5cf84172713a004eb26704342f5) Thanks [@Andarist](https://github.com/Andarist)! - Fixed `EventFrom` helper type to work on machines.
607
-
608
- ## 4.30.3
609
-
610
- ### Patch Changes
611
-
612
- - [#3088](https://github.com/statelyai/xstate/pull/3088) [`9f02271a3`](https://github.com/statelyai/xstate/commit/9f02271a3dd0b314a270f54d4de56af8daab31d1) Thanks [@Andarist](https://github.com/Andarist)! - Added some internal `@ts-ignore` comments to fix consuming projects that do not use `skipLibCheck`.
613
-
614
- * [#3082](https://github.com/statelyai/xstate/pull/3082) [`8d3f2cfea`](https://github.com/statelyai/xstate/commit/8d3f2cfea7b57b6293fd862844400353e2a7451a) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with context type being inferred from too many places within `createMachine` call and possibly ending up as `any` for the entire machine.
615
-
616
- - [#3027](https://github.com/statelyai/xstate/pull/3027) [`97ad964bd`](https://github.com/statelyai/xstate/commit/97ad964bd064ce48c28323052557336ed4def1a9) Thanks [@hedgepigdaniel](https://github.com/hedgepigdaniel)! - Fixed an issue with not being able to call `createMachine` in a generic context when the type for the context was generic and not concrete.
617
-
618
- * [#3084](https://github.com/statelyai/xstate/pull/3084) [`50c271dc1`](https://github.com/statelyai/xstate/commit/50c271dc1a1a05b035364f8247aa4d80d613864f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with context type defined using `schema.context` being sometimes widened based on `config.context`. If both are given the `schema.context` should always take precedence and should represent the complete type of the context.
619
-
620
- - [#3089](https://github.com/statelyai/xstate/pull/3089) [`862697e29`](https://github.com/statelyai/xstate/commit/862697e2990934d46050580d7e09c749d09d8426) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility with Skypack by exporting some shared utilities from root entry of XState and consuming them directly in other packages (this avoids accessing those things using deep imports and thus it avoids creating those compatibility problems).
621
-
622
- * [#3087](https://github.com/statelyai/xstate/pull/3087) [`ae9579497`](https://github.com/statelyai/xstate/commit/ae95794971f765e3f984f4080f8a92236c53cd6c) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `ActorRefFrom` not resolving the typegen metadata from machine types given to it. This could sometimes result in types assignability problems, especially when using machine factories and `spawn`.
623
-
624
- ## 4.30.2
625
-
626
- ### Patch Changes
627
-
628
- - [#3063](https://github.com/statelyai/xstate/pull/3063) [`c826559b4`](https://github.com/statelyai/xstate/commit/c826559b4c495f64c85dd79f1d1262ae9e7d15bf) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a type compatibility with Svelte's readables. It should be possible again to use XState interpreters directly as readables at the type-level.
629
-
630
- * [#3051](https://github.com/statelyai/xstate/pull/3051) [`04091f29c`](https://github.com/statelyai/xstate/commit/04091f29cb80dd8e6c95e42668bd56f02f775973) Thanks [@Andarist](https://github.com/Andarist)! - Fixed type compatibility with functions accepting machines that were created before typegen was a thing in XState. This should make it possible to use the latest version of XState with `@xstate/vue`, `@xstate/react@^1` and some community packages.
631
-
632
- Note that this change doesn't make those functions to accept machines that have typegen information on them. For that the signatures of those functions would have to be adjusted.
633
-
634
- - [#3077](https://github.com/statelyai/xstate/pull/3077) [`2c76ecac5`](https://github.com/statelyai/xstate/commit/2c76ecac5de73fbb3a2376a0f66802480ec9549f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with nested `state.matches` calls when the typegen was involved. The `state` ended up being `never` and thus not usable.
635
-
636
- ## 4.30.1
637
-
638
- ### Patch Changes
639
-
640
- - [#3040](https://github.com/statelyai/xstate/pull/3040) [`18dc2b3e2`](https://github.com/statelyai/xstate/commit/18dc2b3e2c49527b2155063490bb7295f1f06043) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `AnyState` and `AnyStateMachine` types are now available, which can be used to express any state and state machine, respectively:
641
-
642
- ```ts
643
- import type { AnyState, AnyStateMachine } from 'xstate';
644
-
645
- // A function that takes in any state machine
646
- function visualizeMachine(machine: AnyStateMachine) {
647
- // (exercise left to reader)
648
- }
649
-
650
- function logState(state: AnyState) {
651
- // ...
652
- }
653
- ```
654
-
655
- * [#3042](https://github.com/statelyai/xstate/pull/3042) [`e53396f08`](https://github.com/statelyai/xstate/commit/e53396f083091db26c117000ce6ec070914360e9) Thanks [@suerta-git](https://github.com/suerta-git)! - Added the `AnyStateConfig` type, which represents any `StateConfig<...>`:
656
-
657
- ```ts
658
- import type { AnyStateConfig } from 'xstate';
659
- import { State } from 'xstate';
660
-
661
- // Retrieving the state config from localStorage
662
- const stateConfig: AnyStateConfig = JSON.parse(
663
- localStorage.getItem('app-state')
664
- );
665
-
666
- // Use State.create() to restore state from config object with correct type
667
- const previousState = State.create(stateConfig);
668
- ```
669
-
670
- ## 4.30.0
671
-
672
- ### Minor Changes
673
-
674
- - [#2965](https://github.com/statelyai/xstate/pull/2965) [`8b8f719c3`](https://github.com/statelyai/xstate/commit/8b8f719c36ab2c09fcd11b529cc6c9c89a06ad2e) Thanks [@satyasinha](https://github.com/satyasinha)! - All actions are now available in the `actions` variable when importing: `import { actions } from 'xstate'`
675
-
676
- * [#2892](https://github.com/statelyai/xstate/pull/2892) [`02de3d44f`](https://github.com/statelyai/xstate/commit/02de3d44f8ca87b4dcb4153d3560da7d43ee9d0b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Persisted state can now be easily restored to a state compatible with the machine without converting it to a `State` instance first:
677
-
678
- ```js
679
- // Persisting a state
680
- someService.subscribe(state => {
681
- localStorage.setItem('some-state', JSON.stringify(state));
682
- });
683
-
684
- // Restoring a state
685
- const stateJson = localStorage.getItem('some-state');
686
-
687
- // No need to convert `stateJson` object to a state!
688
- const someService = interpret(someMachine).start(stateJson);
689
- ```
690
-
691
- ### Patch Changes
692
-
693
- - [#3012](https://github.com/statelyai/xstate/pull/3012) [`ab431dcb8`](https://github.com/statelyai/xstate/commit/ab431dcb8bd67a3f0bcfc9b6ca31779bb15d14af) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with a reference to `@types/node` being inserted into XState's compiled output. This could cause unexpected issues in projects expecting APIs like `setTimeout` to be typed with browser compatibility in mind.
694
-
695
- * [#3023](https://github.com/statelyai/xstate/pull/3023) [`642e9f5b8`](https://github.com/statelyai/xstate/commit/642e9f5b83dae79f016be8b657d25499077bbcda) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with states created using `machine.getInitialState` not being "resolved" in full. This could cause some things, such as `after` transitions, not being executed correctly after starting an interpreter using such state.
696
-
697
- - [#2982](https://github.com/statelyai/xstate/pull/2982) [`a39145580`](https://github.com/statelyai/xstate/commit/a391455803171dcf03a1a0ec589f9dd603260d63) Thanks [@Andarist](https://github.com/Andarist)! - Marked all phantom properties on the `StateMachine` type as deprecated. This deprioritized them in IDEs so they don't popup as first suggestions during property access.
698
-
699
- * [#2992](https://github.com/statelyai/xstate/pull/2992) [`22737adf2`](https://github.com/statelyai/xstate/commit/22737adf211971197f3809f406ac3bee54dc69f0) Thanks [@Andarist](https://github.com/Andarist), [@mattpocock](https://github.com/mattpocock)! - Fixed an issue with `state.context` becoming `any` after `state.matches` when typegen is used.
700
-
701
- - [#2981](https://github.com/statelyai/xstate/pull/2981) [`edf60d67b`](https://github.com/statelyai/xstate/commit/edf60d67b3ca58eca96c7853410528c4e4abac7b) Thanks [@Andarist](https://github.com/Andarist)! - Moved an internal `@ts-ignore` to a JSDoc-style comment to fix consuming projects that do not use `skipLibCheck`. Regular inline and block comments are not preserved in the TypeScript's emit.
702
-
703
- ## 4.29.0
704
-
705
- ### Minor Changes
706
-
707
- - [#2674](https://github.com/statelyai/xstate/pull/2674) [`1cd26811c`](https://github.com/statelyai/xstate/commit/1cd26811cea441366a082b0f77c7a6ffb135dc38) Thanks [@Andarist](https://github.com/Andarist)! - Using `config.schema` becomes the preferred way of "declaring" TypeScript generics with this release:
708
-
709
- ```js
710
- createMachine({
711
- schema: {
712
- context: {} as { count: number },
713
- events: {} as { type: 'INC' } | { type: 'DEC' }
714
- }
715
- })
716
- ```
717
-
718
- This allows us to leverage the inference algorithm better and unlocks some exciting possibilities for using XState in a more type-strict manner.
719
-
720
- * [#2674](https://github.com/statelyai/xstate/pull/2674) [`1cd26811c`](https://github.com/statelyai/xstate/commit/1cd26811cea441366a082b0f77c7a6ffb135dc38) Thanks [@Andarist](https://github.com/Andarist), [@mattpocock](https://github.com/mattpocock)! - Added the ability to tighten TS declarations of machine with generated metadata. This opens several exciting doors to being able to use typegen seamlessly with XState to provide an amazing typing experience.
721
-
722
- With the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode), you can specify a new attribute called `tsTypes: {}` in your machine definition:
723
-
724
- ```ts
725
- const machine = createMachine({
726
- tsTypes: {}
727
- });
728
- ```
729
-
730
- The extension will automatically add a type assertion to this property, which allows for type-safe access to a lot of XState's API's.
731
-
732
- ⚠️ This feature is in beta. Actions/services/guards/delays might currently get incorrectly annotated if they are called "in response" to always transitions or raised events. We are working on fixing this, both in XState and in the typegen.
733
-
734
- ### Patch Changes
735
-
736
- - [#2962](https://github.com/statelyai/xstate/pull/2962) [`32520650b`](https://github.com/statelyai/xstate/commit/32520650b7d6b43e416b896054033432aaede5d5) Thanks [@mattpocock](https://github.com/mattpocock)! - Added `t()`, which can be used to provide types for `schema` attributes in machine configs:
737
-
738
- ```ts
739
- import { t, createMachine } from 'xstate';
740
-
741
- const machine = createMachine({
742
- schema: {
743
- context: t<{ value: number }>(),
744
- events: t<{ type: 'EVENT_1' } | { type: 'EVENT_2' }>()
745
- }
746
- });
747
- ```
748
-
749
- * [#2957](https://github.com/statelyai/xstate/pull/2957) [`8550ddda7`](https://github.com/statelyai/xstate/commit/8550ddda73e2ad291e19173d7fa8d13e3336fbb9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The repository links have been updated from `github.com/davidkpiano` to `github.com/statelyai`.
750
-
751
- ## 4.28.1
752
-
753
- ### Patch Changes
754
-
755
- - [#2943](https://github.com/statelyai/xstate/pull/2943) [`e9f3f07a1`](https://github.com/statelyai/xstate/commit/e9f3f07a1ee9fe97af7e8f532c5b3dd3c4f73cec) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an infinite loop when initially spawned actor (in an initial context) responded synchronously to its parent.
756
-
757
- * [#2953](https://github.com/statelyai/xstate/pull/2953) [`90fa97008`](https://github.com/statelyai/xstate/commit/90fa97008970283f17a3f2f6aa9b1b7071593e80) Thanks [@Andarist](https://github.com/Andarist)! - Bring back the global type declaration for the `Symbol.observable` to fix consuming projects that do not use `skipLibCheck`.
758
-
759
- - [#2903](https://github.com/statelyai/xstate/pull/2903) [`b6dde9075`](https://github.com/statelyai/xstate/commit/b6dde9075adb3bb3522b4b8f8eeb804d3221a527) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with exit actions being called in random order when stopping a machine. They should always be called in the reversed document order (the ones defined on children should be called before the ones defined on ancestors and the ones defined on states appearing later in the code should be called before the ones defined on their sibling states).
760
-
761
- ## 4.28.0
762
-
763
- ### Minor Changes
764
-
765
- - [#2835](https://github.com/statelyai/xstate/pull/2835) [`029f7b75a`](https://github.com/statelyai/xstate/commit/029f7b75a22a8186e5e3983dfd980c52369ef09f) Thanks [@woutermont](https://github.com/woutermont)! - Added interop observable symbols to `ActorRef` so that actor refs are compatible with libraries like RxJS.
766
-
767
- ### Patch Changes
768
-
769
- - [#2864](https://github.com/statelyai/xstate/pull/2864) [`4252ee212`](https://github.com/statelyai/xstate/commit/4252ee212e59fd074707b933c101662d47938849) Thanks [@davidkpiano](https://github.com/statelyai)! - Generated IDs for invocations that do not provide an `id` are now based on the state ID to avoid collisions:
770
-
771
- ```js
772
- createMachine({
773
- id: 'test',
774
- initial: 'p',
775
- states: {
776
- p: {
777
- type: 'parallel',
778
- states: {
779
- // Before this change, both invoke IDs would be 'someSource',
780
- // which is incorrect.
781
- a: {
782
- invoke: {
783
- src: 'someSource'
784
- // generated invoke ID: 'test.p.a:invocation[0]'
785
- }
786
- },
787
- b: {
788
- invoke: {
789
- src: 'someSource'
790
- // generated invoke ID: 'test.p.b:invocation[0]'
791
- }
792
- }
793
- }
794
- }
795
- }
796
- });
797
- ```
798
-
799
- * [#2925](https://github.com/statelyai/xstate/pull/2925) [`239b4666a`](https://github.com/statelyai/xstate/commit/239b4666ac302d80c028fef47c6e8ab7e0ae2757) Thanks [@devanfarrell](https://github.com/devanfarrell)! - The `sendTo(actorRef, event)` action creator introduced in `4.27.0`, which was not accessible from the package exports, can now be used just like other actions:
800
-
801
- ```js
802
- import { actions } from 'xstate';
803
-
804
- const { sendTo } = actions;
805
- ```
806
-
807
- ## 4.27.0
808
-
809
- ### Minor Changes
810
-
811
- - [#2800](https://github.com/statelyai/xstate/pull/2800) [`759a90155`](https://github.com/statelyai/xstate/commit/759a9015512bbf532d7044afe6a889c04dc7edf6) Thanks [@davidkpiano](https://github.com/statelyai)! - The `sendTo(actorRef, event)` action creator has been introduced. It allows you to specify the recipient actor ref of an event first, so that the event can be strongly typed against the events allowed to be received by the actor ref:
812
-
813
- ```ts
814
- // ...
815
- entry: sendTo(
816
- (ctx) => ctx.someActorRef,
817
- { type: 'EVENT_FOR_ACTOR' }
818
- ),
819
- // ...
820
- ```
821
-
822
- ### Patch Changes
823
-
824
- - [#2804](https://github.com/statelyai/xstate/pull/2804) [`f3caecf5a`](https://github.com/statelyai/xstate/commit/f3caecf5ad384cfe2a843c26333aaa46a77ece68) Thanks [@davidkpiano](https://github.com/statelyai)! - The `state.can(...)` method no longer unnecessarily executes `assign()` actions and instead determines if a given event will change the state by reading transition data before evaluating actions.
825
-
826
- * [#2856](https://github.com/statelyai/xstate/pull/2856) [`49c2e9094`](https://github.com/statelyai/xstate/commit/49c2e90945d369e2dfb2e4fc376b3f46714dce09) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with stopped children sometimes starting their own child actors. This could happen when the child was stopped synchronously (for example by its parent) when transitioning to an invoking state.
827
-
828
- - [#2895](https://github.com/statelyai/xstate/pull/2895) [`df5ffce14`](https://github.com/statelyai/xstate/commit/df5ffce14908d0aa8056a56001039dfd260be1a4) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with some exit handlers being executed more than once when stopping a machine.
829
-
830
- ## 4.26.1
831
-
832
- ### Patch Changes
833
-
834
- - [#2819](https://github.com/statelyai/xstate/pull/2819) [`0d51d33cd`](https://github.com/statelyai/xstate/commit/0d51d33cd6dc6ab876a5554788300282d03fa5d1) Thanks [@simonihmig](https://github.com/simonihmig)! - Support `globalThis` in `getGlobal()` for better compatibility
835
-
836
- * [#2828](https://github.com/statelyai/xstate/pull/2828) [`c0ef3e8`](https://github.com/statelyai/xstate/commit/c0ef3e882c688e6beefb196a3293ec71b65625e3) Thanks [@davidkpiano](https://github.com/statelyai)! - XState is now compatible with TypeScript version 4.5.
837
-
838
- ## 4.26.0
839
-
840
- ### Minor Changes
841
-
842
- - [#2672](https://github.com/statelyai/xstate/pull/2672) [`8e1d05d`](https://github.com/statelyai/xstate/commit/8e1d05dcafab0d1c8a63b07694b3f208850b0b4b) Thanks [@davidkpiano](https://github.com/statelyai)! - The `description` property is a new top-level property for state nodes and transitions, that lets you provide text descriptions:
843
-
844
- ```ts
845
- const machine = createMachine({
846
- // ...
847
- states: {
848
- active: {
849
- // ...
850
- description: 'The task is in progress',
851
- on: {
852
- DEACTIVATE: {
853
- // ...
854
- description: 'Deactivates the task'
855
- }
856
- }
857
- }
858
- }
859
- });
860
- ```
861
-
862
- Future Stately tooling will use the `description` to render automatically generated documentation, type hints, and enhancements to visual tools.
863
-
864
- * [#2743](https://github.com/statelyai/xstate/pull/2743) [`e268bf34a`](https://github.com/statelyai/xstate/commit/e268bf34a0dfe442ef7b43ecf8ab5c8d81ac69fb) Thanks [@janovekj](https://github.com/janovekj)! - Add optional type parameter to narrow type returned by `EventFrom`. You can use it like this:
865
-
866
- ```ts
867
- type UpdateNameEvent = EventFrom<typeof userModel>;
868
- ```
869
-
870
- ### Patch Changes
871
-
872
- - [#2738](https://github.com/statelyai/xstate/pull/2738) [`942fd90e0`](https://github.com/statelyai/xstate/commit/942fd90e0c7a942564dd9c2ffebb93d6c86698df) Thanks [@michelsciortino](https://github.com/michelsciortino)! - The `tags` property was missing from state's definitions. This is used when converting a state to a JSON string. Since this is how we serialize states within [`@xstate/inspect`](https://github.com/statelyai/xstate/tree/main/packages/xstate-inspect) this has caused inspected machines to miss the `tags` information.
873
-
874
- * [#2740](https://github.com/statelyai/xstate/pull/2740) [`707cb981f`](https://github.com/statelyai/xstate/commit/707cb981fdb8a5c75cacb7e9bfa5c7e5a1cc1c88) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with tags being missed on a service state after starting that service using a state value, like this:
875
-
876
- ```js
877
- const service = interpret(machine).start('active');
878
- service.state.hasTag('foo'); // this should now return a correct result
879
- ```
880
-
881
- - [#2691](https://github.com/statelyai/xstate/pull/2691) [`a72806035`](https://github.com/statelyai/xstate/commit/a728060353c9cb9bdb0cd37aacf793498a8750c8) Thanks [@davidkpiano](https://github.com/statelyai)! - Meta data can now be specified for `invoke` configs in the `invoke.meta` property:
882
-
883
- ```js
884
- const machine = createMachine({
885
- // ...
886
- invoke: {
887
- src: (ctx, e) => findUser(ctx.userId),
888
- meta: {
889
- summary: 'Finds user',
890
- updatedAt: '2021-09-...',
891
- version: '4.12.2'
892
- // other descriptive meta properties
893
- }
894
- }
895
- });
896
- ```
897
-
898
- ## 4.25.0
899
-
900
- ### Minor Changes
901
-
902
- - [#2657](https://github.com/statelyai/xstate/pull/2657) [`72155c1b7`](https://github.com/statelyai/xstate/commit/72155c1b7887b94f2d8f7cb73a1af17a591cc74c) Thanks [@mattpocock](https://github.com/mattpocock)! - Removed the ability to pass a model as a generic to `createMachine`, in favour of `model.createMachine`. This lets us cut an overload from the definition of `createMachine`, meaning errors become more targeted and less cryptic.
903
-
904
- This means that this approach is no longer supported:
905
-
906
- ```ts
907
- const model = createModel({});
908
-
909
- const machine = createMachine<typeof model>();
910
- ```
911
-
912
- If you're using this approach, you should use `model.createMachine` instead:
913
-
914
- ```ts
915
- const model = createModel({});
916
-
917
- const machine = model.createMachine();
918
- ```
919
-
920
- ### Patch Changes
921
-
922
- - [#2659](https://github.com/statelyai/xstate/pull/2659) [`7bfeb930d`](https://github.com/statelyai/xstate/commit/7bfeb930d65eb4443c300a2d28aeef3664fcafea) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a regression in the inline actions type inference in models without explicit action creators.
923
-
924
- ```js
925
- const model = createModel(
926
- { foo: 100 },
927
- {
928
- events: {
929
- BAR: () => ({})
930
- }
931
- }
932
- );
933
-
934
- model.createMachine({
935
- // `ctx` was of type `any`
936
- entry: ctx => {},
937
- exit: assign({
938
- // `ctx` was of type `unknown`
939
- foo: ctx => 42
940
- })
941
- });
942
- ```
943
-
944
- ## 4.24.1
945
-
946
- ### Patch Changes
947
-
948
- - [#2649](https://github.com/statelyai/xstate/pull/2649) [`ad611007a`](https://github.com/statelyai/xstate/commit/ad611007a9111e8aefe9d22049ac99072588db9f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with functions used as inline actions not always receiving the correct arguments when used with `preserveActionOrder`.
949
-
950
- ## 4.24.0
951
-
952
- ### Minor Changes
953
-
954
- - [#2546](https://github.com/statelyai/xstate/pull/2546) [`a4cfce18c`](https://github.com/statelyai/xstate/commit/a4cfce18c0c179faef15adf25a75b08903064e28) Thanks [@davidkpiano](https://github.com/statelyai)! - You can now know if an event will cause a state change by using the new `state.can(event)` method, which will return `true` if an interpreted machine will "change" the state when sent the `event`, or `false` otherwise:
955
-
956
- ```js
957
- const machine = createMachine({
958
- initial: 'inactive',
959
- states: {
960
- inactive: {
961
- on: {
962
- TOGGLE: 'active'
963
- }
964
- },
965
- active: {
966
- on: {
967
- DO_SOMETHING: { actions: ['something'] }
968
- }
969
- }
970
- }
971
- });
972
-
973
- const state = machine.initialState;
974
-
975
- state.can('TOGGLE'); // true
976
- state.can('DO_SOMETHING'); // false
977
-
978
- // Also takes in full event objects:
979
- state.can({
980
- type: 'DO_SOMETHING',
981
- data: 42
982
- }); // false
983
- ```
984
-
985
- A state is considered "changed" if any of the following are true:
986
-
987
- - its `state.value` changes
988
- - there are new `state.actions` to be executed
989
- - its `state.context` changes
990
-
991
- See [`state.changed` (documentation)](https://xstate.js.org/docs/guides/states.html#state-changed) for more details.
992
-
993
- ### Patch Changes
994
-
995
- - [#2632](https://github.com/statelyai/xstate/pull/2632) [`f8cf5dfe0`](https://github.com/statelyai/xstate/commit/f8cf5dfe0bf20c8545208ed7b1ade619933004f9) Thanks [@davidkpiano](https://github.com/statelyai)! - A regression was fixed where actions were being typed as `never` if events were specified in `createModel(...)` but not actions:
996
-
997
- ```ts
998
- const model = createModel(
999
- {},
1000
- {
1001
- events: {}
1002
- }
1003
- );
1004
-
1005
- model.createMachine({
1006
- // These actions will cause TS to not compile
1007
- entry: 'someAction',
1008
- exit: { type: 'someObjectAction' }
1009
- });
1010
- ```
1011
-
1012
- ## 4.23.4
1013
-
1014
- ### Patch Changes
1015
-
1016
- - [#2606](https://github.com/statelyai/xstate/pull/2606) [`01e5d7984`](https://github.com/statelyai/xstate/commit/01e5d7984a5441a6980eacdb06d42c2a9398bdff) Thanks [@davidkpiano](https://github.com/statelyai)! - The following utility types were previously returning `never` in some unexpected cases, and are now working as expected:
1017
-
1018
- - `ContextFrom<T>`
1019
- - `EventFrom<T>`
1020
- - `EmittedFrom<T>`
1021
-
1022
- ## 4.23.3
1023
-
1024
- ### Patch Changes
1025
-
1026
- - [#2587](https://github.com/statelyai/xstate/pull/2587) [`5aaa8445c`](https://github.com/statelyai/xstate/commit/5aaa8445c0041c6e9c47285c18e8b71cb2d805a7) Thanks [@Andarist](https://github.com/Andarist)! - Allow for guards to be always resolved from the implementations object. This allows a guard implementation to be updated in the running service by `@xstate/react`.
1027
-
1028
- ## 4.23.2
1029
-
1030
- ### Patch Changes
1031
-
1032
- - [`6c3f15c9`](https://github.com/statelyai/xstate/commit/6c3f15c967c816d5d9d235466e1cb1d030deb4a8) [#2551](https://github.com/statelyai/xstate/pull/2551) Thanks [@mattpocock](https://github.com/mattpocock)! - Widened the \*From utility types to allow extracting from factory functions.
1033
-
1034
- This allows for:
1035
-
1036
- ```ts
1037
- const makeMachine = () => createMachine({});
1038
-
1039
- type Interpreter = InterpreterFrom<typeof makeMachine>;
1040
- type Actor = ActorRefFrom<typeof makeMachine>;
1041
- type Context = ContextFrom<typeof makeMachine>;
1042
- type Event = EventsFrom<typeof makeMachine>;
1043
- ```
1044
-
1045
- This also works for models, behaviours, and other actor types.
1046
-
1047
- The previous method for doing this was a good bit more verbose:
1048
-
1049
- ```ts
1050
- const makeMachine = () => createMachine({});
1051
-
1052
- type Interpreter = InterpreterFrom<ReturnType<typeof machine>>;
1053
- ```
1054
-
1055
- * [`413a4578`](https://github.com/statelyai/xstate/commit/413a4578cded21beffff822d1485a3725457b768) [#2491](https://github.com/statelyai/xstate/pull/2491) Thanks [@davidkpiano](https://github.com/statelyai)! - The custom `.toString()` method on action objects is now removed which improves performance in larger applications (see [#2488](https://github.com/statelyai/xstate/discussions/2488) for more context).
1056
-
1057
- - [`5e1223cd`](https://github.com/statelyai/xstate/commit/5e1223cd58485045b192677753946df2c00eddf7) [#2422](https://github.com/statelyai/xstate/pull/2422) Thanks [@davidkpiano](https://github.com/statelyai)! - The `context` property has been removed from `StateNodeConfig`, as it has never been allowed, nor has it ever done anything. The previous typing was unsafe and allowed `context` to be specified on nested state nodes:
1058
-
1059
- ```ts
1060
- createMachine({
1061
- context: {
1062
- /* ... */
1063
- }, // ✅ This is allowed
1064
- initial: 'inner',
1065
- states: {
1066
- inner: {
1067
- context: {
1068
- /* ... */
1069
- } // ❌ This will no longer compile
1070
- }
1071
- }
1072
- });
1073
- ```
1074
-
1075
- * [`5b70c2ff`](https://github.com/statelyai/xstate/commit/5b70c2ff21cc5d8c6cf1c13b6eb7bb12611a9835) [#2508](https://github.com/statelyai/xstate/pull/2508) Thanks [@davidkpiano](https://github.com/statelyai)! - A race condition occurred when a child service is immediately stopped and the parent service tried to remove it from its undefined state (during its own initialization). This has been fixed, and the race condition no longer occurs. See [this issue](https://github.com/statelyai/xstate/issues/2507) for details.
1076
-
1077
- - [`5a9500d1`](https://github.com/statelyai/xstate/commit/5a9500d1cde9bf2300a85bc81529da83f2d08361) [#2522](https://github.com/statelyai/xstate/pull/2522) Thanks [@farskid](https://github.com/farskid), [@Andarist](https://github.com/Andarist)! - Adjusted TS type definitions of the `withContext` and `withConfig` methods so that they accept "lazy context" now.
1078
-
1079
- Example:
1080
-
1081
- ```js
1082
- const copy = machine.withContext(() => ({
1083
- ref: spawn(() => {})
1084
- }));
1085
- ```
1086
-
1087
- * [`84f9fcae`](https://github.com/statelyai/xstate/commit/84f9fcae7d2b7f99800cc3bf18097ed45c48f0f5) [#2540](https://github.com/statelyai/xstate/pull/2540) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `state.hasTag('someTag')` crashing when the `state` was rehydrated.
1088
-
1089
- - [`c17dd376`](https://github.com/statelyai/xstate/commit/c17dd37621a2ba46967926d550c70a35bba7024c) [#2496](https://github.com/statelyai/xstate/pull/2496) Thanks [@VanTanev](https://github.com/VanTanev)! - Add utility type `EmittedFrom<T>` that extracts `Emitted` type from any type which can emit data
1090
-
1091
- ## 4.23.1
1092
-
1093
- ### Patch Changes
1094
-
1095
- - [`141c91cf`](https://github.com/statelyai/xstate/commit/141c91cffd1d7c1ec2e82186834cb977b72fb4d4) [#2436](https://github.com/statelyai/xstate/pull/2436) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue where, when using `model.createMachine`, state's context was incorrectly inferred as `any` after refinement with `.matches(...)`, e.g.
1096
-
1097
- ```ts
1098
- // `state.context` became `any` erroneously
1099
- if (state.matches('inactive')) {
1100
- console.log(state.context.count);
1101
- }
1102
- ```
1103
-
1104
- ## 4.23.0
1105
-
1106
- ### Minor Changes
1107
-
1108
- - [`7dc7ceb8`](https://github.com/statelyai/xstate/commit/7dc7ceb8707569b48ceb35069125763a701a0a58) [#2379](https://github.com/statelyai/xstate/pull/2379) Thanks [@davidkpiano](https://github.com/statelyai)! - There is a new `.preserveActionOrder` (default: `false`) setting in the machine configuration that preserves the order of actions when set to `true`. Normally, actions are executed in order _except_ for `assign(...)` actions, which are prioritized and executed first. When `.preserveActionOrder` is set to `true`, `assign(...)` actions will _not_ be prioritized, and will instead run in order. As a result, actions will capture the **intermediate `context` values** instead of the resulting `context` value from all `assign(...)` actions.
1109
-
1110
- ```ts
1111
- // With `.preserveActionOrder: true`
1112
- const machine = createMachine({
1113
- context: { count: 0 },
1114
- entry: [
1115
- ctx => console.log(ctx.count), // 0
1116
- assign({ count: ctx => ctx.count + 1 }),
1117
- ctx => console.log(ctx.count), // 1
1118
- assign({ count: ctx => ctx.count + 1 }),
1119
- ctx => console.log(ctx.count) // 2
1120
- ],
1121
- preserveActionOrder: true
1122
- });
1123
-
1124
- // With `.preserveActionOrder: false` (default)
1125
- const machine = createMachine({
1126
- context: { count: 0 },
1127
- entry: [
1128
- ctx => console.log(ctx.count), // 2
1129
- assign({ count: ctx => ctx.count + 1 }),
1130
- ctx => console.log(ctx.count), // 2
1131
- assign({ count: ctx => ctx.count + 1 }),
1132
- ctx => console.log(ctx.count) // 2
1133
- ]
1134
- // preserveActionOrder: false
1135
- });
1136
- ```
1137
-
1138
- ### Patch Changes
1139
-
1140
- - [`4e305372`](https://github.com/statelyai/xstate/commit/4e30537266eb082ccd85f050c9372358247b4167) [#2361](https://github.com/statelyai/xstate/pull/2361) Thanks [@woutermont](https://github.com/woutermont)! - Add type for `Symbol.observable` to the `Interpreter` to improve the compatibility with RxJS.
1141
-
1142
- * [`1def6cf6`](https://github.com/statelyai/xstate/commit/1def6cf6109867a87b4323ee83d20a9ee0c49d7b) [#2374](https://github.com/statelyai/xstate/pull/2374) Thanks [@davidkpiano](https://github.com/statelyai)! - Existing actors can now be identified in `spawn(...)` calls by providing an `id`. This allows them to be referenced by string:
1143
-
1144
- ```ts
1145
- const machine = createMachine({
1146
- context: () => ({
1147
- someRef: spawn(someExistingRef, 'something')
1148
- }),
1149
- on: {
1150
- SOME_EVENT: {
1151
- actions: send('AN_EVENT', { to: 'something' })
1152
- }
1153
- }
1154
- });
1155
- ```
1156
-
1157
- - [`da6861e3`](https://github.com/statelyai/xstate/commit/da6861e34a2b28bf6eeaa7c04a2d4cf9a90f93f1) [#2391](https://github.com/statelyai/xstate/pull/2391) Thanks [@davidkpiano](https://github.com/statelyai)! - There are two new helper types for extracting `context` and `event` types:
1158
-
1159
- - `ContextFrom<T>` which extracts the `context` from any type that uses context
1160
- - `EventFrom<T>` which extracts the `event` type (which extends `EventObject`) from any type which uses events
1161
-
1162
- ## 4.22.0
1163
-
1164
- ### Minor Changes
1165
-
1166
- - [`1b32aa0d`](https://github.com/statelyai/xstate/commit/1b32aa0d3a0eca11ffcb7ec9d710eb8828107aa0) [#2356](https://github.com/statelyai/xstate/pull/2356) Thanks [@davidkpiano](https://github.com/statelyai)! - The model created from `createModel(...)` now provides a `.createMachine(...)` method that does not require passing any generic type parameters:
1167
-
1168
- ```diff
1169
- const model = createModel(/* ... */);
1170
-
1171
- -const machine = createMachine<typeof model>(/* ... */);
1172
- +const machine = model.createMachine(/* ... */);
1173
- ```
1174
-
1175
- * [`432b60f7`](https://github.com/statelyai/xstate/commit/432b60f7bcbcee9510e0d86311abbfd75b1a674e) [#2280](https://github.com/statelyai/xstate/pull/2280) Thanks [@davidkpiano](https://github.com/statelyai)! - Actors can now be invoked/spawned from reducers using the `fromReducer(...)` behavior creator:
1176
-
1177
- ```ts
1178
- import { fromReducer } from 'xstate/lib/behaviors';
1179
-
1180
- type CountEvent = { type: 'INC' } | { type: 'DEC' };
1181
-
1182
- const countReducer = (count: number, event: CountEvent): number => {
1183
- if (event.type === 'INC') {
1184
- return count + 1;
1185
- } else if (event.type === 'DEC') {
1186
- return count - 1;
1187
- }
1188
-
1189
- return count;
1190
- };
1191
-
1192
- const countMachine = createMachine({
1193
- invoke: {
1194
- id: 'count',
1195
- src: () => fromReducer(countReducer, 0)
1196
- },
1197
- on: {
1198
- INC: {
1199
- actions: forwardTo('count')
1200
- },
1201
- DEC: {
1202
- actions: forwardTo('count')
1203
- }
1204
- }
1205
- });
1206
- ```
1207
-
1208
- - [`f9bcea2c`](https://github.com/statelyai/xstate/commit/f9bcea2ce909ac59fcb165b352a7b51a8b29a56d) [#2366](https://github.com/statelyai/xstate/pull/2366) Thanks [@davidkpiano](https://github.com/statelyai)! - Actors can now be spawned directly in the initial `machine.context` using lazy initialization, avoiding the need for intermediate states and unsafe typings for immediately spawned actors:
1209
-
1210
- ```ts
1211
- const machine = createMachine<{ ref: ActorRef<SomeEvent> }>({
1212
- context: () => ({
1213
- ref: spawn(anotherMachine, 'some-id') // spawn immediately!
1214
- })
1215
- // ...
1216
- });
1217
- ```
1218
-
1219
- ## 4.20.2
1220
-
1221
- ### Patch Changes
1222
-
1223
- - [`1ef29e83`](https://github.com/statelyai/xstate/commit/1ef29e83e14331083279d50fd3a8907eb63793eb) [#2343](https://github.com/statelyai/xstate/pull/2343) Thanks [@davidkpiano](https://github.com/statelyai)! - Eventless ("always") transitions will no longer be ignored if an event is sent to a machine in a state that does not have any enabled transitions for that event.
1224
-
1225
- ## 4.20.1
1226
-
1227
- ### Patch Changes
1228
-
1229
- - [`99bc5fb9`](https://github.com/statelyai/xstate/commit/99bc5fb9d1d7be35f4c767dcbbf5287755b306d0) [#2275](https://github.com/statelyai/xstate/pull/2275) Thanks [@davidkpiano](https://github.com/statelyai)! - The `SpawnedActorRef` TypeScript interface has been deprecated in favor of a unified `ActorRef` interface, which contains the following:
1230
-
1231
- ```ts
1232
- interface ActorRef<TEvent extends EventObject, TEmitted = any>
1233
- extends Subscribable<TEmitted> {
1234
- send: (event: TEvent) => void;
1235
- id: string;
1236
- subscribe(observer: Observer<T>): Subscription;
1237
- subscribe(
1238
- next: (value: T) => void,
1239
- error?: (error: any) => void,
1240
- complete?: () => void
1241
- ): Subscription;
1242
- getSnapshot: () => TEmitted | undefined;
1243
- }
1244
- ```
1245
-
1246
- For simpler actor-ref-like objects, the `BaseActorRef<TEvent>` interface has been introduced.
1247
-
1248
- ```ts
1249
- interface BaseActorRef<TEvent extends EventObject> {
1250
- send: (event: TEvent) => void;
1251
- }
1252
- ```
1253
-
1254
- * [`38e6a5e9`](https://github.com/statelyai/xstate/commit/38e6a5e98a1dd54b4f2ef96942180ec0add88f2b) [#2334](https://github.com/statelyai/xstate/pull/2334) Thanks [@davidkpiano](https://github.com/statelyai)! - When using a model type in `createMachine<typeof someModel>(...)`, TypeScript will no longer compile machines that are missing the `context` property in the machine configuration:
1255
-
1256
- ```ts
1257
- const machine = createMachine<typeof someModel>({
1258
- // missing context - will give a TS error!
1259
- // context: someModel.initialContext,
1260
- initial: 'somewhere',
1261
- states: {
1262
- somewhere: {}
1263
- }
1264
- });
1265
- ```
1266
-
1267
- - [`5f790ba5`](https://github.com/statelyai/xstate/commit/5f790ba5478cb733a59e3b0603e8976c11bcdd04) [#2320](https://github.com/statelyai/xstate/pull/2320) Thanks [@davidkpiano](https://github.com/statelyai)! - The typing for `InvokeCallback` have been improved for better event constraints when using the `sendBack` parameter of invoked callbacks:
1268
-
1269
- ```ts
1270
- invoke: () => (sendBack, receive) => {
1271
- // Will now be constrained to events that the parent machine can receive
1272
- sendBack({ type: 'SOME_EVENT' });
1273
- };
1274
- ```
1275
-
1276
- * [`2de3ec3e`](https://github.com/statelyai/xstate/commit/2de3ec3e994e0deb5a142aeac15e1eddeb18d1e1) [#2272](https://github.com/statelyai/xstate/pull/2272) Thanks [@davidkpiano](https://github.com/statelyai)! - The `state.meta` value is now calculated directly from `state.configuration`. This is most useful when starting a service from a persisted state:
1277
-
1278
- ```ts
1279
- const machine = createMachine({
1280
- id: 'test',
1281
- initial: 'first',
1282
- states: {
1283
- first: {
1284
- meta: {
1285
- name: 'first state'
1286
- }
1287
- },
1288
- second: {
1289
- meta: {
1290
- name: 'second state'
1291
- }
1292
- }
1293
- }
1294
- });
1295
-
1296
- const service = interpret(machine);
1297
-
1298
- service.start('second'); // `meta` will be computed
1299
-
1300
- // the state will have
1301
- // meta: {
1302
- // 'test.second': {
1303
- // name: 'second state'
1304
- // }
1305
- // }
1306
- });
1307
- ```
1308
-
1309
- ## 4.20.0
1310
-
1311
- ### Minor Changes
1312
-
1313
- - [`28059b9f`](https://github.com/statelyai/xstate/commit/28059b9f09926d683d80b7d816f5b703c0667a9f) [#2197](https://github.com/statelyai/xstate/pull/2197) Thanks [@davidkpiano](https://github.com/statelyai)! - All spawned and invoked actors now have a `.getSnapshot()` method, which allows you to retrieve the latest value emitted from that actor. That value may be `undefined` if no value has been emitted yet.
1314
-
1315
- ```js
1316
- const machine = createMachine({
1317
- context: {
1318
- promiseRef: null
1319
- },
1320
- initial: 'pending',
1321
- states: {
1322
- pending: {
1323
- entry: assign({
1324
- promiseRef: () => spawn(fetch(/* ... */), 'some-promise')
1325
- })
1326
- }
1327
- }
1328
- });
1329
-
1330
- const service = interpret(machine)
1331
- .onTransition(state => {
1332
- // Read promise value synchronously
1333
- const resolvedValue = state.context.promiseRef?.getSnapshot();
1334
- // => undefined (if promise not resolved yet)
1335
- // => { ... } (resolved data)
1336
- })
1337
- .start();
1338
-
1339
- // ...
1340
- ```
1341
-
1342
- ### Patch Changes
1343
-
1344
- - [`4ef03465`](https://github.com/statelyai/xstate/commit/4ef03465869e27dc878ec600661c9253d90f74f0) [#2240](https://github.com/statelyai/xstate/pull/2240) Thanks [@VanTanev](https://github.com/VanTanev)! - Preserve StateMachine type when .withConfig() and .withContext() modifiers are used on a machine.
1345
-
1346
- ## 4.19.2
1347
-
1348
- ### Patch Changes
1349
-
1350
- - [`18789aa9`](https://github.com/statelyai/xstate/commit/18789aa94669e48b71e2ae22e524d9bbe9dbfc63) [#2107](https://github.com/statelyai/xstate/pull/2107) Thanks [@woutermont](https://github.com/woutermont)! - This update restricts invoked `Subscribable`s to `EventObject`s,
1351
- so that type inference can be done on which `Subscribable`s are
1352
- allowed to be invoked. Existing `MachineConfig`s that invoke
1353
- `Subscribable<any>`s that are not `Subscribable<EventObject>`s
1354
- should be updated accordingly.
1355
-
1356
- * [`38dcec1d`](https://github.com/statelyai/xstate/commit/38dcec1dad60c62cf8c47c88736651483276ff87) [#2149](https://github.com/statelyai/xstate/pull/2149) Thanks [@davidkpiano](https://github.com/statelyai)! - Invocations and entry actions for _combinatorial_ machines (machines with only a single root state) now behave predictably and will not re-execute upon targetless transitions.
1357
-
1358
- ## 4.19.1
1359
-
1360
- ### Patch Changes
1361
-
1362
- - [`64ab1150`](https://github.com/statelyai/xstate/commit/64ab1150e0a383202f4af1d586b28e081009c929) [#2173](https://github.com/statelyai/xstate/pull/2173) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with tags not being set correctly after sending an event to a machine that didn't result in selecting any transitions.
1363
-
1364
- ## 4.19.0
1365
-
1366
- ### Minor Changes
1367
-
1368
- - [`4f2f626d`](https://github.com/statelyai/xstate/commit/4f2f626dc84f45bb18ded6dd9aad3b6f6a2190b1) [#2143](https://github.com/statelyai/xstate/pull/2143) Thanks [@davidkpiano](https://github.com/statelyai)! - Tags can now be added to state node configs under the `.tags` property:
1369
-
1370
- ```js
1371
- const machine = createMachine({
1372
- initial: 'green',
1373
- states: {
1374
- green: {
1375
- tags: 'go' // single tag
1376
- },
1377
- yellow: {
1378
- tags: 'go'
1379
- },
1380
- red: {
1381
- tags: ['stop', 'other'] // multiple tags
1382
- }
1383
- }
1384
- });
1385
- ```
1386
-
1387
- You can query whether a state has a tag via `state.hasTag(tag)`:
1388
-
1389
- ```js
1390
- const canGo = state.hasTag('go');
1391
- // => `true` if in 'green' or 'red' state
1392
- ```
1393
-
1394
- ### Patch Changes
1395
-
1396
- - [`a61d01ce`](https://github.com/statelyai/xstate/commit/a61d01cefab5734adf9bfb167291f5b0ba712684) [#2125](https://github.com/statelyai/xstate/pull/2125) Thanks [@VanTanev](https://github.com/VanTanev)! - In callback invokes, the types of `callback` and `onReceive` are properly scoped to the machine TEvent.
1397
-
1398
- ## 4.18.0
1399
-
1400
- ### Minor Changes
1401
-
1402
- - [`d0939ec6`](https://github.com/statelyai/xstate/commit/d0939ec60161c34b053cecdaeb277606b5982375) [#2046](https://github.com/statelyai/xstate/pull/2046) Thanks [@SimeonC](https://github.com/SimeonC)! - Allow machines to communicate with the inspector even in production builds.
1403
-
1404
- * [`e37fffef`](https://github.com/statelyai/xstate/commit/e37fffefb742f45765945c02727edfbd5e2f9d47) [#2079](https://github.com/statelyai/xstate/pull/2079) Thanks [@davidkpiano](https://github.com/statelyai)! - There is now support for "combinatorial machines" (state machines that only have one state):
1405
-
1406
- ```js
1407
- const testMachine = createMachine({
1408
- context: { value: 42 },
1409
- on: {
1410
- INC: {
1411
- actions: assign({ value: ctx => ctx.value + 1 })
1412
- }
1413
- }
1414
- });
1415
- ```
1416
-
1417
- These machines omit the `initial` and `state` properties, as the entire machine is treated as a single state.
1418
-
1419
- ### Patch Changes
1420
-
1421
- - [`6a9247d4`](https://github.com/statelyai/xstate/commit/6a9247d4d3a39e6c8c4724d3368a13fcdef10907) [#2102](https://github.com/statelyai/xstate/pull/2102) Thanks [@VanTanev](https://github.com/VanTanev)! - Provide a convenience type for getting the `Interpreter` type based on the `StateMachine` type by transferring all generic parameters onto it. It can be used like this: `InterpreterFrom<typeof machine>`
1422
-
1423
- ## 4.17.1
1424
-
1425
- ### Patch Changes
1426
-
1427
- - [`33302814`](https://github.com/statelyai/xstate/commit/33302814c38587d0044afd2ae61a4ff4779416c6) [#2041](https://github.com/statelyai/xstate/pull/2041) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with creatorless models not being correctly matched by `createMachine`'s overload responsible for using model-induced types.
1428
-
1429
- ## 4.17.0
1430
-
1431
- ### Minor Changes
1432
-
1433
- - [`7763db8d`](https://github.com/statelyai/xstate/commit/7763db8d3615321d03839b2bd31c9b118ddee50c) [#1977](https://github.com/statelyai/xstate/pull/1977) Thanks [@davidkpiano](https://github.com/statelyai)! - The `schema` property has been introduced to the machine config passed into `createMachine(machineConfig)`, which allows you to provide metadata for the following:
1434
-
1435
- - Context
1436
- - Events
1437
- - Actions
1438
- - Guards
1439
- - Services
1440
-
1441
- This metadata can be accessed as-is from `machine.schema`:
1442
-
1443
- ```js
1444
- const machine = createMachine({
1445
- schema: {
1446
- // Example in JSON Schema (anything can be used)
1447
- context: {
1448
- type: 'object',
1449
- properties: {
1450
- foo: { type: 'string' },
1451
- bar: { type: 'number' },
1452
- baz: {
1453
- type: 'object',
1454
- properties: {
1455
- one: { type: 'string' }
1456
- }
1457
- }
1458
- }
1459
- },
1460
- events: {
1461
- FOO: { type: 'object' },
1462
- BAR: { type: 'object' }
1463
- }
1464
- }
1465
- // ...
1466
- });
1467
- ```
1468
-
1469
- Additionally, the new `createSchema()` identity function allows any schema "metadata" to be represented by a specific type, which makes type inference easier without having to specify generic types:
1470
-
1471
- ```ts
1472
- import { createSchema, createMachine } from 'xstate';
1473
-
1474
- // Both `context` and `events` are inferred in the rest of the machine!
1475
- const machine = createMachine({
1476
- schema: {
1477
- context: createSchema<{ count: number }>(),
1478
- // No arguments necessary
1479
- events: createSchema<{ type: 'FOO' } | { type: 'BAR' }>()
1480
- }
1481
- // ...
1482
- });
1483
- ```
1484
-
1485
- * [`5febfe83`](https://github.com/statelyai/xstate/commit/5febfe83a7e5e866c0a4523ea4f86a966af7c50f) [#1955](https://github.com/statelyai/xstate/pull/1955) Thanks [@davidkpiano](https://github.com/statelyai)! - Event creators can now be modeled inside of the 2nd argument of `createModel()`, and types for both `context` and `events` will be inferred properly in `createMachine()` when given the `typeof model` as the first generic parameter.
1486
-
1487
- ```ts
1488
- import { createModel } from 'xstate/lib/model';
1489
-
1490
- const userModel = createModel(
1491
- // initial context
1492
- {
1493
- name: 'David',
1494
- age: 30
1495
- },
1496
- // creators (just events for now)
1497
- {
1498
- events: {
1499
- updateName: (value: string) => ({ value }),
1500
- updateAge: (value: number) => ({ value }),
1501
- anotherEvent: () => ({}) // no payload
1502
- }
1503
- }
1504
- );
1505
-
1506
- const machine = createMachine<typeof userModel>({
1507
- context: userModel.initialContext,
1508
- initial: 'active',
1509
- states: {
1510
- active: {
1511
- on: {
1512
- updateName: {
1513
- /* ... */
1514
- },
1515
- updateAge: {
1516
- /* ... */
1517
- }
1518
- }
1519
- }
1520
- }
1521
- });
1522
-
1523
- const nextState = machine.transition(
1524
- undefined,
1525
- userModel.events.updateName('David')
1526
- );
1527
- ```
1528
-
1529
- ## 4.16.2
1530
-
1531
- ### Patch Changes
1532
-
1533
- - [`4194ffe8`](https://github.com/statelyai/xstate/commit/4194ffe84cfe7910e2c183701e36bc5cac5c9bcc) [#1710](https://github.com/statelyai/xstate/pull/1710) Thanks [@davidkpiano](https://github.com/statelyai)! - Stopping an already stopped interpreter will no longer crash. See [#1697](https://github.com/statelyai/xstate/issues/1697) for details.
1534
-
1535
- ## 4.16.1
1536
-
1537
- ### Patch Changes
1538
-
1539
- - [`af6b7c70`](https://github.com/statelyai/xstate/commit/af6b7c70015db29d84f79dfd29ea0dc221b8f3e6) [#1865](https://github.com/statelyai/xstate/pull/1865) Thanks [@Andarist](https://github.com/Andarist)! - Improved `.matches(value)` inference for typestates containing union types as values.
1540
-
1541
- ## 4.16.0
1542
-
1543
- ### Minor Changes
1544
-
1545
- - [`d2e328f8`](https://github.com/statelyai/xstate/commit/d2e328f8efad7e8d3500d39976d1153a26e835a3) [#1439](https://github.com/statelyai/xstate/pull/1439) Thanks [@davidkpiano](https://github.com/statelyai)! - An opt-in `createModel()` helper has been introduced to make it easier to work with typed `context` and events.
1546
-
1547
- - `createModel(initialContext)` creates a `model` object
1548
- - `model.initialContext` returns the `initialContext`
1549
- - `model.assign(assigner, event?)` creates an `assign` action that is properly scoped to the `event` in TypeScript
1550
-
1551
- See https://github.com/statelyai/xstate/pull/1439 for more details.
1552
-
1553
- ```js
1554
- import { createMachine } from 'xstate';
1555
- import { createModel } from 'xstate/lib/model'; // opt-in, not part of main build
1556
-
1557
- interface UserContext {
1558
- name: string;
1559
- age: number;
1560
- }
1561
-
1562
- type UserEvents =
1563
- | { type: 'updateName'; value: string }
1564
- | { type: 'updateAge'; value: number }
1565
-
1566
- const userModel = createModel<UserContext, UserEvents>({
1567
- name: 'David',
1568
- age: 30
1569
- });
1570
-
1571
- const assignName = userModel.assign({
1572
- name: (_, e) => e.value // correctly typed to `string`
1573
- }, 'updateName'); // restrict to 'updateName' event
1574
-
1575
- const machine = createMachine<UserContext, UserEvents>({
1576
- context: userModel.context,
1577
- initial: 'active',
1578
- states: {
1579
- active: {
1580
- on: {
1581
- updateName: {
1582
- actions: assignName
1583
- }
1584
- }
1585
- }
1586
- }
1587
- });
1588
- ```
1589
-
1590
- ## 4.15.4
1591
-
1592
- ### Patch Changes
1593
-
1594
- - [`0cb8df9b`](https://github.com/statelyai/xstate/commit/0cb8df9b6c8cd01ada82afe967bf1015e24e75d9) [#1816](https://github.com/statelyai/xstate/pull/1816) Thanks [@Andarist](https://github.com/Andarist)! - `machine.resolveState(state)` calls should resolve to the correct value of `.done` property now.
1595
-
1596
- ## 4.15.3
1597
-
1598
- ### Patch Changes
1599
-
1600
- - [`63ba888e`](https://github.com/statelyai/xstate/commit/63ba888e19bd2b72f9aad2c9cd36cde297e0ffe5) [#1770](https://github.com/statelyai/xstate/pull/1770) Thanks [@davidkpiano](https://github.com/statelyai)! - Instead of referencing `window` directly, XState now internally calls a `getGlobal()` function that will resolve to the proper `globalThis` value in all environments. This affects the dev tools code only.
1601
-
1602
- ## 4.15.2
1603
-
1604
- ### Patch Changes
1605
-
1606
- - [`497c543d`](https://github.com/statelyai/xstate/commit/497c543d2980ea1a277b30b340a7bcd3dd0b3cb6) [#1766](https://github.com/statelyai/xstate/pull/1766) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with events received from callback actors not having the appropriate `_event.origin` set.
1607
-
1608
- ## 4.15.1
1609
-
1610
- ### Patch Changes
1611
-
1612
- - [`8a8cfa32`](https://github.com/statelyai/xstate/commit/8a8cfa32d99aedf11f4af93ba56fa9ba68925c74) [#1704](https://github.com/statelyai/xstate/pull/1704) Thanks [@blimmer](https://github.com/blimmer)! - The default `clock` methods (`setTimeout` and `clearTimeout`) are now invoked properly with the global context preserved for those invocations which matter for some JS environments. More details can be found in the corresponding issue: [#1703](https://github.com/statelyai/xstate/issues/1703).
1613
-
1614
- ## 4.15.0
1615
-
1616
- ### Minor Changes
1617
-
1618
- - [`6596d0ba`](https://github.com/statelyai/xstate/commit/6596d0ba163341fc43d214b48115536cb4815b68) [#1622](https://github.com/statelyai/xstate/pull/1622) Thanks [@davidkpiano](https://github.com/statelyai)! - Spawned/invoked actors and interpreters are now typed as extending `ActorRef` (e.g., `SpawnedActorRef`) rather than `Actor` or `Interpreter`. This unification of types should make it more straightforward to provide actor types:
1619
-
1620
- ```diff
1621
- import {
1622
- - Actor
1623
- + ActorRef
1624
- } from 'xstate';
1625
-
1626
- // ...
1627
-
1628
- interface SomeContext {
1629
- - server?: Actor;
1630
- + server?: ActorRef<ServerEvent>;
1631
- }
1632
- ```
1633
-
1634
- It's also easier to specify the type of a spawned/invoked machine with `ActorRefFrom`:
1635
-
1636
- ```diff
1637
- import {
1638
- createMachine,
1639
- - Actor
1640
- + ActorRefFrom
1641
- } from 'xstate';
1642
-
1643
- const serverMachine = createMachine<ServerContext, ServerEvent>({
1644
- // ...
1645
- });
1646
-
1647
- interface SomeContext {
1648
- - server?: Actor; // difficult to type
1649
- + server?: ActorRefFrom<typeof serverMachine>;
1650
- }
1651
- ```
1652
-
1653
- ### Patch Changes
1654
-
1655
- - [`75a91b07`](https://github.com/statelyai/xstate/commit/75a91b078a10a86f13edc9eec3ac1d6246607002) [#1692](https://github.com/statelyai/xstate/pull/1692) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with history state entering a wrong state if the most recent visit in its parent has been caused by a transient transition.
1656
-
1657
- ## 4.14.1
1658
-
1659
- ### Patch Changes
1660
-
1661
- - [`02c76350`](https://github.com/statelyai/xstate/commit/02c763504da0808eeb281587981a5baf8ba884a1) [#1656](https://github.com/statelyai/xstate/pull/1656) Thanks [@Andarist](https://github.com/Andarist)! - Exit actions will now be properly called when a service gets canceled by calling its `stop` method.
1662
-
1663
- ## 4.14.0
1664
-
1665
- ### Minor Changes
1666
-
1667
- - [`119db8fb`](https://github.com/statelyai/xstate/commit/119db8fbccd08f899e1275a502d8c4c51b5a130e) [#1577](https://github.com/statelyai/xstate/pull/1577) Thanks [@davidkpiano](https://github.com/statelyai)! - Expressions can now be used in the `stop()` action creator:
1668
-
1669
- ```js
1670
- // ...
1671
- actions: stop(context => context.someActor);
1672
- ```
1673
-
1674
- ### Patch Changes
1675
-
1676
- - [`8c78e120`](https://github.com/statelyai/xstate/commit/8c78e1205a729d933e30db01cd4260d82352a9be) [#1570](https://github.com/statelyai/xstate/pull/1570) Thanks [@davidkpiano](https://github.com/statelyai)! - The return type of `spawn(machine)` will now be `Actor<State<TContext, TEvent>, TEvent>`, which is a supertype of `Interpreter<...>`.
1677
-
1678
- * [`602687c2`](https://github.com/statelyai/xstate/commit/602687c235c56cca552c2d5a9d78adf224f522d8) [#1566](https://github.com/statelyai/xstate/pull/1566) Thanks [@davidkpiano](https://github.com/statelyai)! - Exit actions will now be properly called when an invoked machine reaches its final state. See [#1109](https://github.com/statelyai/xstate/issues/1109) for more details.
1679
-
1680
- - [`6e44d02a`](https://github.com/statelyai/xstate/commit/6e44d02ad03af4041046120dd6c975e3b5b3772a) [#1553](https://github.com/statelyai/xstate/pull/1553) Thanks [@davidkpiano](https://github.com/statelyai)! - The `state.children` property now properly shows all spawned and invoked actors. See [#795](https://github.com/statelyai/xstate/issues/795) for more details.
1681
-
1682
- * [`72b0880e`](https://github.com/statelyai/xstate/commit/72b0880e6444ae009adca72088872bb5c0760ce3) [#1504](https://github.com/statelyai/xstate/pull/1504) Thanks [@Andarist](https://github.com/Andarist)! - Added `status` property on the `Interpreter` - this can be used to differentiate not started, running and stopped interpreters. This property is best compared to values on the new `InterpreterStatus` export.
1683
-
1684
- ## 4.13.0
1685
-
1686
- ### Minor Changes
1687
-
1688
- - [`f51614df`](https://github.com/statelyai/xstate/commit/f51614dff760cfe4511c0bc7cca3d022157c104c) [#1409](https://github.com/statelyai/xstate/pull/1409) Thanks [@jirutka](https://github.com/jirutka)! - Fix type `ExtractStateValue` so that it generates a type actually describing a `State.value`
1689
-
1690
- ### Patch Changes
1691
-
1692
- - [`b1684ead`](https://github.com/statelyai/xstate/commit/b1684eadb1f859db5c733b8d403afc825c294948) [#1402](https://github.com/statelyai/xstate/pull/1402) Thanks [@Andarist](https://github.com/Andarist)! - Improved TypeScript type-checking performance a little bit by using distributive conditional type within `TransitionsConfigArray` declarations instead of a mapped type. Kudos to [@amcasey](https://github.com/amcasey), some discussion around this can be found [here](https://github.com/microsoft/TypeScript/issues/39826#issuecomment-675790689)
1693
-
1694
- * [`ad3026d4`](https://github.com/statelyai/xstate/commit/ad3026d4309e9a1c719e09fd8c15cdfefce22055) [#1407](https://github.com/statelyai/xstate/pull/1407) Thanks [@tomenden](https://github.com/tomenden)! - Fixed an issue with not being able to run XState in Web Workers due to assuming that `window` or `global` object is available in the executing environment, but none of those are actually available in the Web Workers context.
1695
-
1696
- - [`4e949ec8`](https://github.com/statelyai/xstate/commit/4e949ec856349062352562c825beb0654e528f81) [#1401](https://github.com/statelyai/xstate/pull/1401) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with spawned actors being spawned multiple times when they got spawned in an initial state of a child machine that is invoked in the initial state of a parent machine.
1697
-
1698
- <details>
1699
- <summary>
1700
- Illustrating example for curious readers.
1701
- </summary>
1702
-
1703
- ```js
1704
- const child = createMachine({
1705
- initial: 'bar',
1706
- context: {},
1707
- states: {
1708
- bar: {
1709
- entry: assign({
1710
- promise: () => {
1711
- return spawn(() => Promise.resolve('answer'));
1712
- }
1713
- })
1714
- }
1715
- }
1716
- });
1717
-
1718
- const parent = createMachine({
1719
- initial: 'foo',
1720
- states: {
1721
- foo: {
1722
- invoke: {
1723
- src: child,
1724
- onDone: 'end'
1725
- }
1726
- },
1727
- end: { type: 'final' }
1728
- }
1729
- });
1730
-
1731
- interpret(parent).start();
1732
- ```
1733
-
1734
- </details>
1735
-
1736
- ## 4.12.0
1737
-
1738
- ### Minor Changes
1739
-
1740
- - [`b72e29dd`](https://github.com/statelyai/xstate/commit/b72e29dd728b4c1be4bdeaec93909b4e307db5cf) [#1354](https://github.com/statelyai/xstate/pull/1354) Thanks [@davidkpiano](https://github.com/statelyai)! - The `Action` type was simplified, and as a result, you should see better TypeScript performance.
1741
-
1742
- * [`4dbabfe7`](https://github.com/statelyai/xstate/commit/4dbabfe7d5ba154e852b4d460a2434c6fc955726) [#1320](https://github.com/statelyai/xstate/pull/1320) Thanks [@davidkpiano](https://github.com/statelyai)! - The `invoke.src` property now accepts an object that describes the invoke source with its `type` and other related metadata. This can be read from the `services` option in the `meta.src` argument:
1743
-
1744
- ```js
1745
- const machine = createMachine(
1746
- {
1747
- initial: 'searching',
1748
- states: {
1749
- searching: {
1750
- invoke: {
1751
- src: {
1752
- type: 'search',
1753
- endpoint: 'example.com'
1754
- }
1755
- // ...
1756
- }
1757
- // ...
1758
- }
1759
- }
1760
- },
1761
- {
1762
- services: {
1763
- search: (context, event, { src }) => {
1764
- console.log(src);
1765
- // => { endpoint: 'example.com' }
1766
- }
1767
- }
1768
- }
1769
- );
1770
- ```
1771
-
1772
- Specifying a string for `invoke.src` will continue to work the same; e.g., if `src: 'search'` was specified, this would be the same as `src: { type: 'search' }`.
1773
-
1774
- - [`8662e543`](https://github.com/statelyai/xstate/commit/8662e543393de7e2f8a6d92ff847043781d10f4d) [#1317](https://github.com/statelyai/xstate/pull/1317) Thanks [@Andarist](https://github.com/Andarist)! - All `TTypestate` type parameters default to `{ value: any; context: TContext }` now and the parametrized type is passed correctly between various types which results in more accurate types involving typestates.
1775
-
1776
- ### Patch Changes
1777
-
1778
- - [`3ab3f25e`](https://github.com/statelyai/xstate/commit/3ab3f25ea297e4d770eef512e9583475c943845d) [#1285](https://github.com/statelyai/xstate/pull/1285) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with initial state of invoked machines being read without custom data passed to them which could lead to a crash when evaluating transient transitions for the initial state.
1779
-
1780
- * [`a7da1451`](https://github.com/statelyai/xstate/commit/a7da14510fd1645ad041836b567771edb5b90827) [#1290](https://github.com/statelyai/xstate/pull/1290) Thanks [@davidkpiano](https://github.com/statelyai)! - The "Attempted to spawn an Actor [...] outside of a service. This will have no effect." warnings are now silenced for "lazily spawned" actors, which are actors that aren't immediately active until the function that creates them are called:
1781
-
1782
- ```js
1783
- // ⚠️ "active" actor - will warn
1784
- spawn(somePromise);
1785
-
1786
- // 🕐 "lazy" actor - won't warn
1787
- spawn(() => somePromise);
1788
-
1789
- // 🕐 machines are also "lazy" - won't warn
1790
- spawn(someMachine);
1791
- ```
1792
-
1793
- It is recommended that all `spawn(...)`-ed actors are lazy, to avoid accidentally initializing them e.g., when reading `machine.initialState` or calculating otherwise pure transitions. In V5, this will be enforced.
1794
-
1795
- - [`c1f3d260`](https://github.com/statelyai/xstate/commit/c1f3d26069ee70343f8045a48411e02a68f98cbd) [#1317](https://github.com/statelyai/xstate/pull/1317) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a type returned by a `raise` action - it's now `RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>` instead of `RaiseAction<TEvent> | SendAction<TContext, TEvent, TEvent>`. This makes it comaptible in a broader range of scenarios.
1796
-
1797
- * [`8270d5a7`](https://github.com/statelyai/xstate/commit/8270d5a76c71add3a5109e069bd85716b230b5d4) [#1372](https://github.com/statelyai/xstate/pull/1372) Thanks [@christianchown](https://github.com/christianchown)! - Narrowed the `ServiceConfig` type definition to use a specific event type to prevent compilation errors on strictly-typed `MachineOptions`.
1798
-
1799
- - [`01e3e2dc`](https://github.com/statelyai/xstate/commit/01e3e2dcead63dce3eef5ab745395584efbf05fa) [#1320](https://github.com/statelyai/xstate/pull/1320) Thanks [@davidkpiano](https://github.com/statelyai)! - The JSON definition for `stateNode.invoke` objects will no longer include the `onDone` and `onError` transitions, since those transitions are already merged into the `transitions` array. This solves the issue of reviving a serialized machine from JSON, where before, the `onDone` and `onError` transitions for invocations were wrongly duplicated.
1800
-
1801
- ## 4.11.0
1802
-
1803
- ### Minor Changes
1804
-
1805
- - [`36ed8d0a`](https://github.com/statelyai/xstate/commit/36ed8d0a3adf5b7fd187b0abe198220398e8b056) [#1262](https://github.com/statelyai/xstate/pull/1262) Thanks [@Andarist](https://github.com/Andarist)! - Improved type inference for `InvokeConfig['data']`. This has required renaming `data` property on `StateNode` instances to `doneData`. This property was never meant to be a part of the public API, so we don't consider this to be a breaking change.
1806
-
1807
- * [`2c75ab82`](https://github.com/statelyai/xstate/commit/2c75ab822e49cb1a23c1e14eb7bd04548ab143eb) [#1219](https://github.com/statelyai/xstate/pull/1219) Thanks [@davidkpiano](https://github.com/statelyai)! - The resolved value of the `invoke.data` property is now available in the "invoke meta" object, which is passed as the 3rd argument to the service creator in `options.services`. This will work for all types of invoked services now, including promises, observables, and callbacks.
1808
-
1809
- ```js
1810
- const machine = createMachine({
1811
- initial: 'pending',
1812
- context: {
1813
- id: 42
1814
- },
1815
- states: {
1816
- pending: {
1817
- invoke: {
1818
- src: 'fetchUser',
1819
- data: {
1820
- userId: (context) => context.id
1821
- },
1822
- onDone: 'success'
1823
- }
1824
- },
1825
- success: {
1826
- type: 'final'
1827
- }
1828
- }
1829
- },
1830
- {
1831
- services: {
1832
- fetchUser: (ctx, _, { data }) => {
1833
- return fetch(`some/api/user/${data.userId}`)
1834
- .then(response => response.json());
1835
- }
1836
- }
1837
- }
1838
- ```
1839
-
1840
- - [`a6c78ae9`](https://github.com/statelyai/xstate/commit/a6c78ae960acba36b61a41a5d154ea59908010b0) [#1249](https://github.com/statelyai/xstate/pull/1249) Thanks [@davidkpiano](https://github.com/statelyai)! - New property introduced for eventless (transient) transitions: **`always`**, which indicates a transition that is always taken when in that state. Empty string transition configs for [transient transitions](https://xstate.js.org/docs/guides/transitions.html#transient-transitions) are deprecated in favor of `always`:
1841
-
1842
- ```diff
1843
- // ...
1844
- states: {
1845
- playing: {
1846
- + always: [
1847
- + { target: 'win', cond: 'didPlayerWin' },
1848
- + { target: 'lose', cond: 'didPlayerLose' },
1849
- + ],
1850
- on: {
1851
- // ⚠️ Deprecation warning
1852
- - '': [
1853
- - { target: 'win', cond: 'didPlayerWin' },
1854
- - { target: 'lose', cond: 'didPlayerLose' },
1855
- - ]
1856
- }
1857
- }
1858
- }
1859
- // ...
1860
- ```
1861
-
1862
- The old empty string syntax (`'': ...`) will continue to work until V5.
1863
-
1864
- ### Patch Changes
1865
-
1866
- - [`36ed8d0a`](https://github.com/statelyai/xstate/commit/36ed8d0a3adf5b7fd187b0abe198220398e8b056) [#1262](https://github.com/statelyai/xstate/pull/1262) Thanks [@Andarist](https://github.com/Andarist)! - `StateMachine<any, any, any>` is no longer a part of the `InvokeConfig` type, but rather it creates a union with `InvokeConfig` in places where it is needed. This change shouldn't affect consumers' code.
1867
-
1868
- ## 4.10.0
1869
-
1870
- ### Minor Changes
1871
-
1872
- - [`0133954`](https://github.com/statelyai/xstate/commit/013395463b955e950ab24cb4be51faf524b0de6e) [#1178](https://github.com/statelyai/xstate/pull/1178) Thanks [@davidkpiano](https://github.com/statelyai)! - The types for the `send()` and `sendParent()` action creators have been changed to fix the issue of only being able to send events that the machine can receive. In reality, a machine can and should send events to other actors that it might not be able to receive itself. See [#711](https://github.com/statelyai/xstate/issues/711) for more information.
1873
-
1874
- * [`a1f1239`](https://github.com/statelyai/xstate/commit/a1f1239e20e05e338ed994d031e7ef6f2f09ad68) [#1189](https://github.com/statelyai/xstate/pull/1189) Thanks [@davidkpiano](https://github.com/statelyai)! - Previously, `state.matches(...)` was problematic because it was casting `state` to `never` if it didn't match the state value. This is now fixed by making the `Typestate` resolution more granular.
1875
-
1876
- - [`dbc6a16`](https://github.com/statelyai/xstate/commit/dbc6a161c068a3e12dd12452b68a66fe3f4fb8eb) [#1183](https://github.com/statelyai/xstate/pull/1183) Thanks [@davidkpiano](https://github.com/statelyai)! - Actions from a restored state provided as a custom initial state to `interpret(machine).start(initialState)` are now executed properly. See #1174 for more information.
1877
-
1878
- ### Patch Changes
1879
-
1880
- - [`a10d604`](https://github.com/statelyai/xstate/commit/a10d604a6afcf39048b02be5436acdd197f16c2b) [#1176](https://github.com/statelyai/xstate/pull/1176) Thanks [@itfarrier](https://github.com/itfarrier)! - Fix passing state schema into State generic
1881
-
1882
- * [`326db72`](https://github.com/statelyai/xstate/commit/326db725e50f7678af162626c6c7491e4364ec07) [#1185](https://github.com/statelyai/xstate/pull/1185) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with invoked service not being correctly started if other service got stopped in a subsequent microstep (in response to raised or null event).
1883
-
1884
- - [`c3a496e`](https://github.com/statelyai/xstate/commit/c3a496e1f92ec27db0643fd1ddc32d683db4e751) [#1160](https://github.com/statelyai/xstate/pull/1160) Thanks [@davidkpiano](https://github.com/statelyai)! - Delayed transitions defined using `after` were previously causing a circular dependency when the machine was converted using `.toJSON()`. This has now been fixed.
1885
-
1886
- * [`e16e48e`](https://github.com/statelyai/xstate/commit/e16e48e05e6243a3eacca58a13d3e663cd641f55) [#1153](https://github.com/statelyai/xstate/pull/1153) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `choose` and `pure` not being able to use actions defined in options.
1887
-
1888
- - [`d496ecb`](https://github.com/statelyai/xstate/commit/d496ecb11b26011f2382d1ce6c4433284a7b3e9b) [#1165](https://github.com/statelyai/xstate/pull/1165) Thanks [@davidkpiano](https://github.com/statelyai)! - XState will now warn if you define an `.onDone` transition on the root node. Root nodes which are "done" represent the machine being in its final state, and can no longer accept any events. This has been reported as confusing in [#1111](https://github.com/statelyai/xstate/issues/1111).
1889
-
1890
- ## 4.9.1
1891
-
1892
- ### Patch Changes
1893
-
1894
- - [`8a97785`](https://github.com/statelyai/xstate/commit/8a97785055faaeb1b36040dd4dc04e3b90fa9ec2) [#1137](https://github.com/statelyai/xstate/pull/1137) Thanks [@davidkpiano](https://github.com/statelyai)! - Added docs for the `choose()` and `pure()` action creators, as well as exporting the `pure()` action creator in the `actions` object.
1895
-
1896
- * [`e65dee9`](https://github.com/statelyai/xstate/commit/e65dee928fea60df1e9f83c82fed8102dfed0000) [#1131](https://github.com/statelyai/xstate/pull/1131) Thanks [@wKovacs64](https://github.com/wKovacs64)! - Include the new `choose` action in the `actions` export from the `xstate` core package. This was missed in v4.9.0.
1897
-
1898
- ## 4.9.0
1899
-
1900
- ### Minor Changes
1901
-
1902
- - [`f3ff150`](https://github.com/statelyai/xstate/commit/f3ff150f7c50f402704d25cdc053b76836e447e3) [#1103](https://github.com/statelyai/xstate/pull/1103) Thanks [@davidkpiano](https://github.com/statelyai)! - Simplify the `TransitionConfigArray` and `TransitionConfigMap` types in order to fix excessively deep type instantiation TypeScript reports. This addresses [#1015](https://github.com/statelyai/xstate/issues/1015).
1903
-
1904
- * [`6c47b66`](https://github.com/statelyai/xstate/commit/6c47b66c3289ff161dc96d9b246873f55c9e18f2) [#1076](https://github.com/statelyai/xstate/pull/1076) Thanks [@Andarist](https://github.com/Andarist)! - Added support for conditional actions. It's possible now to have actions executed based on conditions using following:
1905
-
1906
- ```js
1907
- entry: [
1908
- choose([
1909
- { cond: ctx => ctx > 100, actions: raise('TOGGLE') },
1910
- {
1911
- cond: 'hasMagicBottle',
1912
- actions: [assign(ctx => ({ counter: ctx.counter + 1 }))]
1913
- },
1914
- { actions: ['fallbackAction'] }
1915
- ])
1916
- ];
1917
- ```
1918
-
1919
- It works very similar to the if-else syntax where only the first matched condition is causing associated actions to be executed and the last ones can be unconditional (serving as a general fallback, just like else branch).
1920
-
1921
- ### Patch Changes
1922
-
1923
- - [`1a129f0`](https://github.com/statelyai/xstate/commit/1a129f0f35995981c160d756a570df76396bfdbd) [#1073](https://github.com/statelyai/xstate/pull/1073) Thanks [@Andarist](https://github.com/Andarist)! - Cleanup internal structures upon receiving termination events from spawned actors.
1924
-
1925
- * [`e88aa18`](https://github.com/statelyai/xstate/commit/e88aa18431629e1061b74dfd4a961b910e274e0b) [#1085](https://github.com/statelyai/xstate/pull/1085) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with data expressions of root's final nodes being called twice.
1926
-
1927
- - [`88b17b2`](https://github.com/statelyai/xstate/commit/88b17b2476ff9a0fbe810df9d00db32c2241cd6e) [#1090](https://github.com/statelyai/xstate/pull/1090) Thanks [@rjdestigter](https://github.com/rjdestigter)! - This change carries forward the typestate type information encoded in the arguments of the following functions and assures that the return type also has the same typestate type information:
1928
-
1929
- - Cloned state machine returned by `.withConfig`.
1930
- - `.state` getter defined for services.
1931
- - `start` method of services.
1932
-
1933
- * [`d5f622f`](https://github.com/statelyai/xstate/commit/d5f622f68f4065a2615b5a4a1caae6b508b4840e) [#1069](https://github.com/statelyai/xstate/pull/1069) Thanks [@davidkpiano](https://github.com/statelyai)! - Loosened event type for `SendAction<TContext, AnyEventObject>`
1934
-
1935
- ## 4.8.0
1936
-
1937
- ### Minor Changes
1938
-
1939
- - [`55aa589`](https://github.com/statelyai/xstate/commit/55aa589648a9afbd153e8b8e74cbf2e0ebf573fb) [#960](https://github.com/statelyai/xstate/pull/960) Thanks [@davidkpiano](https://github.com/statelyai)! - The machine can now be safely JSON-serialized, using `JSON.stringify(machine)`. The shape of this serialization is defined in `machine.schema.json` and reflected in `machine.definition`.
1940
-
1941
- Note that `onEntry` and `onExit` have been deprecated in the definition in favor of `entry` and `exit`.
1942
-
1943
- ### Patch Changes
1944
-
1945
- - [`1ae31c1`](https://github.com/statelyai/xstate/commit/1ae31c17dc81fb63e699b4b9bf1cf4ead023001d) [#1023](https://github.com/statelyai/xstate/pull/1023) Thanks [@Andarist](https://github.com/Andarist)! - Fixed memory leak - `State` objects had been retained in closures.
1946
-
1947
- ## 4.7.8
1948
-
1949
- ### Patch Changes
1950
-
1951
- - [`520580b`](https://github.com/statelyai/xstate/commit/520580b4af597f7c83c329757ae972278c2d4494) [#967](https://github.com/statelyai/xstate/pull/967) Thanks [@andrewgordstewart](https://github.com/andrewgordstewart)! - Add context & event types to InvokeConfig
1952
-
1953
- ## 4.7.7
1954
-
1955
- ### Patch Changes
1956
-
1957
- - [`c8db035`](https://github.com/statelyai/xstate/commit/c8db035b90a7ab4a557359d493d3dd7973dacbdd) [#936](https://github.com/statelyai/xstate/pull/936) Thanks [@davidkpiano](https://github.com/statelyai)! - The `escalate()` action can now take in an expression, which will be evaluated against the `context`, `event`, and `meta` to return the error data.
1958
-
1959
- * [`2a3fea1`](https://github.com/statelyai/xstate/commit/2a3fea18dcd5be18880ad64007d44947cc327d0d) [#952](https://github.com/statelyai/xstate/pull/952) Thanks [@davidkpiano](https://github.com/statelyai)! - The typings for the raise() action have been fixed to allow any event to be raised. This typed behavior will be refined in version 5, to limit raised events to those that the machine accepts.
1960
-
1961
- - [`f86d419`](https://github.com/statelyai/xstate/commit/f86d41979ed108e2ac4df63299fc16f798da69f7) [#957](https://github.com/statelyai/xstate/pull/957) Thanks [@Andarist](https://github.com/Andarist)! - Fixed memory leak - each created service has been registered in internal map but it was never removed from it. Registration has been moved to a point where Interpreter is being started and it's deregistered when it is being stopped.
1962
-
1963
- ## 4.7.6
1964
-
1965
- ### Patch Changes
1966
-
1967
- - dae8818: Typestates are now propagated to interpreted services.
1968
-
1969
- ## 4.7.5
1970
-
1971
- ### Patch Changes
1972
-
1973
- - 6b3d767: Fixed issue with delayed transitions scheduling a delayed event for each transition defined for a single delay.
1974
-
1975
- ## 4.7.4
1976
-
1977
- ### Patch Changes
1978
-
1979
- - 9b043cd: The initial state is now cached inside of the service instance instead of the machine, which was the previous (faulty) strategy. This will prevent entry actions on initial states from being called more than once, which is important for ensuring that actors are not spawned more than once.
1980
-
1981
- ## 4.7.3
1982
-
1983
- ### Patch Changes
1984
-
1985
- - 2b134eee: Fixed issue with events being forwarded to children after being processed by the current machine. Events are now always forwarded first.
1986
- - 2b134eee: Fixed issue with not being able to spawn an actor when processing an event batch.