Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into andarist/wildcards-fo…
Browse files Browse the repository at this point in the history
…r-errors

# Conflicts:
#	packages/core/src/interpreter.ts
#	packages/core/test/invoke.test.ts
  • Loading branch information
Andarist committed Sep 19, 2023
2 parents ddba455 + 6236980 commit 8d402c2
Show file tree
Hide file tree
Showing 1,232 changed files with 116,233 additions and 53,185 deletions.
14 changes: 14 additions & 0 deletions .changeset/beige-pianos-give.md
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';
```
9 changes: 9 additions & 0 deletions .changeset/beige-schools-smash.md
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 }) => { ... });
```
5 changes: 5 additions & 0 deletions .changeset/big-avocados-raise.md
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.
25 changes: 25 additions & 0 deletions .changeset/bright-hotels-sleep.md
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
}
});
```
27 changes: 27 additions & 0 deletions .changeset/bright-needles-visit.md
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.
5 changes: 5 additions & 0 deletions .changeset/calm-experts-design.md
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.
30 changes: 30 additions & 0 deletions .changeset/chatty-monkeys-nail.md
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.
```
17 changes: 17 additions & 0 deletions .changeset/chatty-parrots-reflect.md
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');
```
5 changes: 5 additions & 0 deletions .changeset/chatty-ways-perform.md
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`
16 changes: 16 additions & 0 deletions .changeset/chilled-bobcats-lay.md
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.
5 changes: 5 additions & 0 deletions .changeset/chilled-crews-matter.md
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`
5 changes: 5 additions & 0 deletions .changeset/clean-pens-buy.md
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.
24 changes: 24 additions & 0 deletions .changeset/cold-steaks-drop.md
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;
// => {}
```
18 changes: 11 additions & 7 deletions .changeset/config.json
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
}
}
49 changes: 49 additions & 0 deletions .changeset/cool-grapes-suffer.md
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();
```
5 changes: 5 additions & 0 deletions .changeset/cool-hairs-build.md
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`
5 changes: 5 additions & 0 deletions .changeset/cool-pets-love.md
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.
5 changes: 5 additions & 0 deletions .changeset/curvy-feet-guess.md
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`.
5 changes: 5 additions & 0 deletions .changeset/curvy-seahorses-obey.md
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.
5 changes: 5 additions & 0 deletions .changeset/dirty-birds-sniff.md
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).
33 changes: 33 additions & 0 deletions .changeset/dull-actors-suffer.md
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'
}
}
}
});
```
14 changes: 14 additions & 0 deletions .changeset/eight-guests-wait.md
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);
```
5 changes: 5 additions & 0 deletions .changeset/eighty-chefs-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': major
---

Renamed `machine.withConfig(...)` to `machine.provide(...)`.
5 changes: 5 additions & 0 deletions .changeset/eighty-coins-tease.md
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' })`.
5 changes: 5 additions & 0 deletions .changeset/eighty-trainers-compare.md
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.
18 changes: 18 additions & 0 deletions .changeset/eleven-forks-sleep.md
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, ...)
```
Loading

0 comments on commit 8d402c2

Please sign in to comment.