xstate 4.31.0 → 5.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +526 -0
- package/actions/ExecutableAction.ts +58 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +32 -0
- package/actions/dist/xstate-actions.cjs.js +7 -0
- package/actions/dist/xstate-actions.cjs.prod.js +32 -0
- package/actions/dist/xstate-actions.esm.js +2 -0
- package/actions/dynamicAction.ts +34 -0
- package/actions/package.json +4 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +21 -0
- package/actors/dist/xstate-actors.cjs.js +7 -0
- package/actors/dist/xstate-actors.cjs.prod.js +21 -0
- package/actors/dist/xstate-actors.esm.js +2 -0
- package/actors/package.json +4 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.dev.js +11 -0
- package/dev/dist/xstate-dev.cjs.js +7 -0
- package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
- package/dev/dist/xstate-dev.esm.js +1 -0
- package/dev/package.json +4 -0
- package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
- package/dist/Machine-dca041dc.cjs.prod.js +749 -0
- package/dist/Machine-fb2f47f5.esm.js +751 -0
- package/dist/actions-6b86876d.cjs.dev.js +4815 -0
- package/dist/actions-70094c93.cjs.prod.js +4765 -0
- package/dist/actions-ff512f16.esm.js +4757 -0
- package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
- package/dist/declarations/actions/dynamicAction.d.ts +3 -0
- package/dist/declarations/src/Machine.d.ts +4 -0
- package/dist/declarations/src/Mailbox.d.ts +12 -0
- package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
- package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
- package/dist/declarations/src/State.d.ts +104 -0
- package/dist/declarations/src/StateMachine.d.ts +112 -0
- package/dist/declarations/src/StateNode.d.ts +127 -0
- package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
- package/dist/declarations/src/actions/assign.d.ts +7 -0
- package/dist/declarations/src/actions/cancel.d.ts +10 -0
- package/dist/declarations/src/actions/choose.d.ts +3 -0
- package/dist/declarations/src/actions/invoke.d.ts +3 -0
- package/dist/declarations/src/actions/log.d.ts +11 -0
- package/dist/declarations/src/actions/pure.d.ts +3 -0
- package/dist/declarations/src/actions/raise.d.ts +9 -0
- package/dist/declarations/src/actions/send.d.ts +55 -0
- package/dist/declarations/src/actions/stop.d.ts +8 -0
- package/dist/declarations/src/actions.d.ts +44 -0
- package/dist/declarations/src/actors.d.ts +38 -0
- package/dist/declarations/src/constants.d.ts +5 -0
- package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
- package/{es → dist/declarations/src}/environment.d.ts +0 -1
- package/dist/declarations/src/guards.d.ts +9 -0
- package/dist/declarations/src/index.d.ts +47 -0
- package/dist/declarations/src/interpreter.d.ts +147 -0
- package/{es → dist/declarations/src}/mapState.d.ts +0 -1
- package/dist/declarations/src/match.d.ts +5 -0
- package/dist/declarations/src/memo.d.ts +1 -0
- package/dist/declarations/src/model.d.ts +5 -0
- package/{lib → dist/declarations/src}/model.types.d.ts +10 -9
- package/dist/declarations/src/registry.d.ts +8 -0
- package/{es → dist/declarations/src}/schema.d.ts +0 -1
- package/dist/declarations/src/spawn.d.ts +2 -0
- package/dist/declarations/src/stateUtils.d.ts +85 -0
- package/{lib → dist/declarations/src}/typegenTypes.d.ts +28 -26
- package/dist/declarations/src/types.d.ts +1026 -0
- package/dist/declarations/src/utils.d.ts +56 -0
- package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
- package/dist/index-2a564d03.cjs.dev.js +64 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.dev.js +217 -0
- package/dist/xstate.cjs.js +7 -0
- package/dist/xstate.cjs.prod.js +217 -0
- package/dist/xstate.esm.js +172 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +15 -0
- package/guards/dist/xstate-guards.cjs.js +7 -0
- package/guards/dist/xstate-guards.cjs.prod.js +15 -0
- package/guards/dist/xstate-guards.esm.js +2 -0
- package/guards/package.json +4 -0
- package/invoke/package.json +4 -0
- package/model/dist/xstate-model.cjs.d.ts +1 -0
- package/model/dist/xstate-model.cjs.dev.js +41 -0
- package/model/dist/xstate-model.cjs.js +7 -0
- package/model/dist/xstate-model.cjs.prod.js +41 -0
- package/model/dist/xstate-model.esm.js +37 -0
- package/model/package.json +4 -0
- package/package.json +21 -30
- package/dist/xstate.interpreter.js +0 -15
- package/dist/xstate.js +0 -15
- package/dist/xstate.web.js +0 -15
- package/es/Actor.d.ts +0 -25
- package/es/Actor.js +0 -99
- package/es/Machine.d.ts +0 -12
- package/es/Machine.js +0 -14
- package/es/SimulatedClock.d.ts +0 -17
- package/es/SimulatedClock.js +0 -81
- package/es/State.d.ts +0 -123
- package/es/State.js +0 -274
- package/es/StateNode.d.ts +0 -287
- package/es/StateNode.js +0 -1566
- package/es/_virtual/_tslib.js +0 -78
- package/es/actionTypes.js +0 -22
- package/es/actions.d.ts +0 -154
- package/es/actions.js +0 -520
- package/es/behaviors.d.ts +0 -37
- package/es/behaviors.js +0 -131
- package/es/constants.d.ts +0 -6
- package/es/constants.js +0 -6
- package/es/devTools.d.ts +0 -14
- package/es/each.d.ts +0 -4
- package/es/each.js +0 -13
- package/es/environment.js +0 -3
- package/es/index.d.ts +0 -22
- package/es/index.js +0 -23
- package/es/interpreter.d.ts +0 -209
- package/es/interpreter.js +0 -1402
- package/es/invoke.d.ts +0 -11
- package/es/invokeUtils.d.ts +0 -7
- package/es/invokeUtils.js +0 -40
- package/es/json.d.ts +0 -31
- package/es/json.js +0 -86
- package/es/mapState.js +0 -32
- package/es/match.d.ts +0 -9
- package/es/match.js +0 -34
- package/es/model.d.ts +0 -5
- package/es/model.js +0 -50
- package/es/model.types.d.ts +0 -52
- package/es/patterns.d.ts +0 -14
- package/es/patterns.js +0 -48
- package/es/registry.d.ts +0 -9
- package/es/registry.js +0 -19
- package/es/scheduler.d.ts +0 -17
- package/es/scheduler.js +0 -79
- package/es/schema.js +0 -6
- package/es/scxml.d.ts +0 -6
- package/es/serviceScope.d.ts +0 -4
- package/es/serviceScope.js +0 -16
- package/es/stateUtils.d.ts +0 -17
- package/es/stateUtils.js +0 -259
- package/es/typegenTypes.d.ts +0 -130
- package/es/types.d.ts +0 -1037
- package/es/types.js +0 -33
- package/es/utils.d.ts +0 -72
- package/es/utils.js +0 -626
- package/es/waitFor.d.ts +0 -32
- package/es/waitFor.js +0 -66
- package/lib/Actor.d.ts +0 -25
- package/lib/Actor.js +0 -108
- package/lib/Machine.d.ts +0 -12
- package/lib/Machine.js +0 -19
- package/lib/SimulatedClock.js +0 -85
- package/lib/State.d.ts +0 -123
- package/lib/State.js +0 -282
- package/lib/StateNode.d.ts +0 -287
- package/lib/StateNode.js +0 -1570
- package/lib/_virtual/_tslib.js +0 -85
- package/lib/actionTypes.d.ts +0 -20
- package/lib/actionTypes.js +0 -43
- package/lib/actions.d.ts +0 -154
- package/lib/actions.js +0 -552
- package/lib/behaviors.d.ts +0 -37
- package/lib/behaviors.js +0 -137
- package/lib/constants.d.ts +0 -6
- package/lib/constants.js +0 -13
- package/lib/each.d.ts +0 -4
- package/lib/each.js +0 -17
- package/lib/environment.d.ts +0 -2
- package/lib/environment.js +0 -7
- package/lib/index.d.ts +0 -22
- package/lib/index.js +0 -60
- package/lib/interpreter.d.ts +0 -209
- package/lib/interpreter.js +0 -1408
- package/lib/invoke.d.ts +0 -11
- package/lib/invoke.js +0 -20
- package/lib/invokeUtils.d.ts +0 -7
- package/lib/invokeUtils.js +0 -45
- package/lib/json.d.ts +0 -31
- package/lib/json.js +0 -94
- package/lib/mapState.d.ts +0 -4
- package/lib/mapState.js +0 -36
- package/lib/match.d.ts +0 -9
- package/lib/match.js +0 -38
- package/lib/model.d.ts +0 -5
- package/lib/model.js +0 -54
- package/lib/model.types.js +0 -2
- package/lib/patterns.d.ts +0 -14
- package/lib/patterns.js +0 -53
- package/lib/registry.d.ts +0 -9
- package/lib/registry.js +0 -23
- package/lib/scheduler.d.ts +0 -17
- package/lib/scheduler.js +0 -83
- package/lib/schema.d.ts +0 -3
- package/lib/schema.js +0 -11
- package/lib/scxml.d.ts +0 -6
- package/lib/scxml.js +0 -350
- package/lib/serviceScope.d.ts +0 -4
- package/lib/serviceScope.js +0 -21
- package/lib/stateUtils.d.ts +0 -17
- package/lib/stateUtils.js +0 -273
- package/lib/typegenTypes.js +0 -2
- package/lib/types.d.ts +0 -1037
- package/lib/types.js +0 -35
- package/lib/utils.d.ts +0 -72
- package/lib/utils.js +0 -673
- package/lib/waitFor.d.ts +0 -32
- package/lib/waitFor.js +0 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,531 @@
|
|
|
1
1
|
# xstate
|
|
2
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
|
+
|
|
3
529
|
## 4.31.0
|
|
4
530
|
|
|
5
531
|
### Minor Changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { State } from '../src/State';
|
|
2
|
+
import { TypegenDisabled } from '../src/typegenTypes';
|
|
3
|
+
import {
|
|
4
|
+
ActionFunction,
|
|
5
|
+
BaseActionObject,
|
|
6
|
+
EventObject,
|
|
7
|
+
MachineContext
|
|
8
|
+
} from '../src/types';
|
|
9
|
+
|
|
10
|
+
export interface ResolvedActionObject<
|
|
11
|
+
TContext extends MachineContext,
|
|
12
|
+
TEvent extends EventObject,
|
|
13
|
+
TResolvedTypesMeta = TypegenDisabled
|
|
14
|
+
> {
|
|
15
|
+
type: string;
|
|
16
|
+
params: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* The intermediate context
|
|
19
|
+
*/
|
|
20
|
+
context: TContext | undefined;
|
|
21
|
+
execute: (state: State<TContext, TEvent, TResolvedTypesMeta>) => any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// TODO: refactor out of class
|
|
25
|
+
export class ExecutableAction<
|
|
26
|
+
TContext extends object,
|
|
27
|
+
TEvent extends EventObject,
|
|
28
|
+
TResolvedTypesMeta = TypegenDisabled
|
|
29
|
+
> implements ResolvedActionObject<TContext, TEvent, TResolvedTypesMeta> {
|
|
30
|
+
public type: string;
|
|
31
|
+
public params: Record<string, any>;
|
|
32
|
+
public context: TContext | undefined = undefined;
|
|
33
|
+
constructor(
|
|
34
|
+
public actionObject: BaseActionObject,
|
|
35
|
+
private _exec?: ActionFunction<TContext, TEvent>
|
|
36
|
+
) {
|
|
37
|
+
this.type = actionObject.type;
|
|
38
|
+
this.params = actionObject.params ?? {};
|
|
39
|
+
}
|
|
40
|
+
public execute(state: State<TContext, TEvent, TResolvedTypesMeta>) {
|
|
41
|
+
const context = this.context ?? state.context;
|
|
42
|
+
|
|
43
|
+
return this._exec?.(context, state.event, {
|
|
44
|
+
action: this.actionObject,
|
|
45
|
+
_event: state._event,
|
|
46
|
+
state
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
public setContext(context: TContext) {
|
|
50
|
+
this.context = context;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isExecutableAction(
|
|
55
|
+
action: BaseActionObject | ResolvedActionObject<any, any, any>
|
|
56
|
+
): action is ExecutableAction<any, any, any> {
|
|
57
|
+
return 'execute' in action && typeof action.execute === 'function';
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/actions";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/actions-6b86876d.cjs.dev.js');
|
|
6
|
+
require('../../dist/index-2a564d03.cjs.dev.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.actionTypes = guards_dist_xstateGuards.actionTypes;
|
|
11
|
+
exports.after = guards_dist_xstateGuards.after;
|
|
12
|
+
exports.assign = guards_dist_xstateGuards.assign;
|
|
13
|
+
exports.cancel = guards_dist_xstateGuards.cancel;
|
|
14
|
+
exports.choose = guards_dist_xstateGuards.choose;
|
|
15
|
+
exports.done = guards_dist_xstateGuards.done;
|
|
16
|
+
exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
|
|
17
|
+
exports.error = guards_dist_xstateGuards.error;
|
|
18
|
+
exports.escalate = guards_dist_xstateGuards.escalate;
|
|
19
|
+
exports.forwardTo = guards_dist_xstateGuards.forwardTo;
|
|
20
|
+
exports.getActionFunction = guards_dist_xstateGuards.getActionFunction;
|
|
21
|
+
exports.initEvent = guards_dist_xstateGuards.initEvent;
|
|
22
|
+
exports.log = guards_dist_xstateGuards.log;
|
|
23
|
+
exports.raise = guards_dist_xstateGuards.raise;
|
|
24
|
+
exports.resolveActionObject = guards_dist_xstateGuards.resolveActionObject;
|
|
25
|
+
exports.respond = guards_dist_xstateGuards.respond;
|
|
26
|
+
exports.send = guards_dist_xstateGuards.send;
|
|
27
|
+
exports.sendParent = guards_dist_xstateGuards.sendParent;
|
|
28
|
+
exports.sendTo = guards_dist_xstateGuards.sendTo;
|
|
29
|
+
exports.sendUpdate = guards_dist_xstateGuards.sendUpdate;
|
|
30
|
+
exports.stop = guards_dist_xstateGuards.stop;
|
|
31
|
+
exports.toActionObject = guards_dist_xstateGuards.toActionObject;
|
|
32
|
+
exports.toActionObjects = guards_dist_xstateGuards.toActionObjects;
|