-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/next' into andarist/wildcards-fo…
…r-errors # Conflicts: # packages/core/src/interpreter.ts # packages/core/test/invoke.test.ts
- Loading branch information
Showing
1,232 changed files
with
116,233 additions
and
53,185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
Actor types are now exported from `xstate`: | ||
|
||
```ts | ||
import { | ||
type CallbackActorLogic, | ||
type ObservableActorLogic, | ||
type PromiseActorLogic, | ||
type TransitionActorLogic | ||
} from 'xstate'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
Merge `sendBack` and `receive` with other properties of `fromCallback` logic creator. | ||
|
||
```ts | ||
const callbackLogic = fromCallback(({ input, system, self, sendBack, receive }) => { ... }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/react': minor | ||
--- | ||
|
||
The `useMachine` function is aliased to `useActor` and not shown as visually deprecated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
If context types are specified in the machine config, the `context` property will now be required: | ||
|
||
```ts | ||
// ❌ TS error | ||
createMachine({ | ||
types: {} as { | ||
context: { count: number }; | ||
} | ||
// Missing context property | ||
}); | ||
|
||
// ✅ OK | ||
createMachine({ | ||
types: {} as { | ||
context: { count: number }; | ||
}, | ||
context: { | ||
count: 0 | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
- The third argument of `machine.transition(state, event)` has been removed. The `context` should always be given as part of the `state`. | ||
|
||
- 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. | ||
|
||
- 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). | ||
|
||
- 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. | ||
|
||
- The `stateNode.isTransient` property is removed from `StateNode`. | ||
|
||
- The `.initial` property of a state node config object can now contain executable content (i.e., actions): | ||
|
||
```js | ||
// ... | ||
initial: { | ||
target: 'someTarget', | ||
actions: [/* initial actions */] | ||
} | ||
``` | ||
|
||
- 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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
`spawn` can now benefit from the actor types. Its arguments are strongly-typed based on them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
An error will be thrown if an `initial` state key is not specified for compound state nodes. For example: | ||
|
||
```js | ||
const lightMachine = createMachine({ | ||
id: 'light', | ||
initial: 'green', | ||
states: { | ||
green: {}, | ||
yellow: {}, | ||
red: { | ||
// Forgotten initial state: | ||
// initial: 'walk', | ||
states: { | ||
walk: {}, | ||
wait: {} | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
You will get the error: | ||
|
||
``` | ||
No initial state specified for state node "#light.red". Try adding { initial: "walk" } to the state config. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
IDs for delayed events are no longer derived from event types so this won't work automatically: | ||
|
||
```ts | ||
entry: raise({ type: 'TIMER' }, { delay: 200 }); | ||
exit: cancel('TIMER'); | ||
``` | ||
|
||
Please use explicit IDs: | ||
|
||
```ts | ||
entry: raise({ type: 'TIMER' }, { delay: 200, id: 'myTimer' }); | ||
exit: cancel('myTimer'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': patch | ||
--- | ||
|
||
The `machine.options` property has been renamed to `machine.implementations` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
Significant improvements to error handling have been made: | ||
|
||
- Actors will no longer crash when an error is thrown in an observer (`actor.subscribe(observer)`). | ||
- Errors will be handled by observer's `.error()` handler: | ||
```ts | ||
actor.subscribe({ | ||
error: (error) => { | ||
// handle error | ||
} | ||
}); | ||
``` | ||
- If an observer does not have an error handler, the error will be thrown in a clear stack so bug tracking services can collect it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/react': patch | ||
--- | ||
|
||
Releasing adjusted internals to make the alpha version of this module compatible with the current version of `xstate@alpha` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': patch | ||
--- | ||
|
||
Fixed an issue with inline actions not being correctly executed when there was an equally named action provided through the `implementations` argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
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: | ||
|
||
```ts | ||
const machine = createMachine({ | ||
// This will produce the TS error: | ||
// "Type 'string' is not assignable to type 'object | undefined'" | ||
context: 'some string' | ||
}); | ||
``` | ||
|
||
If `context` is `undefined`, it will now default to an empty object `{}`: | ||
|
||
```ts | ||
const machine = createMachine({ | ||
// No context | ||
}); | ||
|
||
machine.initialState.context; | ||
// => {} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ "repo": "davidkpiano/xstate" } | ||
], | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "statelyai/xstate" }], | ||
"commit": false, | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"ignore": ["@xstate/analytics", "@xstate/scxml"], | ||
"ignore": [ | ||
"@xstate/analytics", | ||
"@xstate/immer", | ||
"@xstate/inspect", | ||
"@xstate/solid", | ||
"@xstate/svelte" | ||
], | ||
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { | ||
"onlyUpdatePeerDependentsWhenOutOfRange": true | ||
"onlyUpdatePeerDependentsWhenOutOfRange": true, | ||
"useCalculatedVersionForSnapshots": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
Actors are now always part of a "system", which is a collection of actors that can communicate with each other. Systems are implicitly created, and can be used to get and set references to any actor in the system via the `key` prop: | ||
|
||
```js | ||
const machine = createMachine({ | ||
// ... | ||
invoke: { | ||
src: emailMachine, | ||
// Registers `emailMachine` as `emailer` on the system | ||
key: 'emailer' | ||
} | ||
}); | ||
``` | ||
|
||
```js | ||
const machine = createMachine({ | ||
// ... | ||
entry: assign({ | ||
emailer: (ctx, ev, { spawn }) => spawn(emailMachine, { key: 'emailer' }) | ||
}) | ||
}); | ||
``` | ||
|
||
Any invoked/spawned actor that is part of a system will be able to reference that actor: | ||
|
||
```js | ||
const anotherMachine = createMachine({ | ||
// ... | ||
entry: sendTo( | ||
(ctx, ev, { system }) => { | ||
return system.get('emailer'); | ||
}, | ||
{ type: 'SEND_EMAIL', subject: 'Hello', body: 'World' } | ||
) | ||
}); | ||
``` | ||
|
||
Each top-level `interpret(...)` call creates a separate implicit system. In this example example, `actor1` and `actor2` are part of different systems and are unrelated: | ||
|
||
```js | ||
// Implicit system | ||
const actor1 = interpret(machine).start(); | ||
|
||
// Another implicit system | ||
const actor2 = interpret(machine).start(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
`external` property on transitions has been renamed to `reenter` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
The `interpreter.onStop(...)` method has been removed. Use an observer instead via `interpreter.subscribe({ complete() { ... } })` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
`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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': patch | ||
--- | ||
|
||
Fixed type-related issue that prevented guards `not('checkFoo')` from being used in machines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/inspect': patch | ||
--- | ||
|
||
Fix crash when sending circular state objects (#2373). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
Partial event descriptors are now type-safe: | ||
|
||
```ts | ||
createMachine({ | ||
types: {} as { | ||
events: | ||
| { type: 'mouse.click.up'; direction: 'up' } | ||
| { type: 'mouse.click.down'; direction: 'down' } | ||
| { type: 'mouse.move' } | ||
| { type: 'keypress' }; | ||
}, | ||
on: { | ||
'mouse.click.*': { | ||
actions: ({ event }) => { | ||
event.type; | ||
// 'mouse.click.up' | 'mouse.click.down' | ||
event.direction; | ||
// 'up' | 'down' | ||
} | ||
}, | ||
'mouse.*': { | ||
actions: ({ event }) => { | ||
event.type; | ||
// 'mouse.click.up' | 'mouse.click.down' | 'mouse.move' | ||
} | ||
} | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
All generic types containing `TContext` and `TEvent` will now follow the same, consistent order: | ||
|
||
1. `TContext` | ||
2. `TEvent` | ||
3. ... All other generic types, including `TStateSchema,`TTypestate`, etc. | ||
|
||
```diff | ||
-const service = interpret<SomeCtx, SomeSchema, SomeEvent>(someMachine); | ||
+const service = interpret<SomeCtx, SomeEvent, SomeSchema>(someMachine); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
Renamed `machine.withConfig(...)` to `machine.provide(...)`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
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', { type: 'TIMER' }, { elapsed: 100 })`, you should do this - `machine.transition(State.from('green', { elapsed: 100 }), { type: 'TIMER' })`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
Sending a string event to `actor.send('some string')` will now throw a proper error message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
The `self` actor reference is now available in all action metas. This makes it easier to reference the "self" `ActorRef` so that actions such as `sendTo` can include it in the event payload: | ||
|
||
```ts | ||
// Sender | ||
actions: sendTo('somewhere', (ctx, ev, { self }) => ({ | ||
type: 'EVENT', | ||
ref: self | ||
})), | ||
|
||
// ... | ||
|
||
// Responder | ||
actions: sendTo((ctx, ev) => ev.ref, ...) | ||
``` |
Oops, something went wrong.