Skip to content

Commit

Permalink
update all main
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarmarina committed Jun 26, 2024
1 parent 6b51fd6 commit fdddbda
Show file tree
Hide file tree
Showing 29 changed files with 854 additions and 152 deletions.
3 changes: 0 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const { constants } = require('jest-config');
module.exports = {
prettierPath: null,
setupFilesAfterEnv: ['@xstate-repo/jest-utils/setup'],
transformIgnorePatterns: [
'node_modules/(?!(@open-wc|lit-html|lit-element|lit|@lit)/)'
],
transform: {
[constants.DEFAULT_JS_PATTERN]: 'babel-jest',
'^.+\\.vue$': '@vue/vue3-jest',
Expand Down
225 changes: 225 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,230 @@
# xstate

## 5.14.0

### Minor Changes

- [#4936](https://github.com/statelyai/xstate/pull/4936) [`c58b36dc3`](https://github.com/statelyai/xstate/commit/c58b36dc35991e20ba5d3c6e212e075f9b27f37d) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Inspecting an actor system via `actor.system.inspect(ev => …)` now accepts a function or observer, and returns a subscription:

```ts
const actor = createActor(someMachine);

const sub = actor.system.inspect((inspectionEvent) => {
console.log(inspectionEvent);
});

// Inspection events will be logged
actor.start();
actor.send({ type: 'anEvent' });

// ...

sub.unsubscribe();

// Will no longer log inspection events
actor.send({ type: 'someEvent' });
```

- [#4942](https://github.com/statelyai/xstate/pull/4942) [`9caaa1f70`](https://github.com/statelyai/xstate/commit/9caaa1f7039f2f50096afd3885560dd40f6f17c0) Thanks [@boneskull](https://github.com/boneskull)! - `DoneActorEvent` and `ErrorActorEvent` now contain property `actorId`, which refers to the ID of the actor the event refers to.

- [#4935](https://github.com/statelyai/xstate/pull/4935) [`2ac08b700`](https://github.com/statelyai/xstate/commit/2ac08b70054e8c6699051b7fafa450af95f7e483) Thanks [@davidkpiano](https://github.com/davidkpiano)! - All actor logic creators now support [emitting events](https://stately.ai/docs/event-emitter):

**Promise actors**

```ts
const logic = fromPromise(async ({ emit }) => {
// ...
emit({
type: 'emitted',
msg: 'hello'
});
// ...
});
```

**Transition actors**

```ts
const logic = fromTransition((state, event, { emit }) => {
// ...
emit({
type: 'emitted',
msg: 'hello'
});
// ...
return state;
}, {});
```

**Observable actors**

```ts
const logic = fromObservable(({ emit }) => {
// ...

emit({
type: 'emitted',
msg: 'hello'
});

// ...
});
```

**Callback actors**

```ts
const logic = fromCallback(({ emit }) => {
// ...
emit({
type: 'emitted',
msg: 'hello'
});
// ...
});
```

### Patch Changes

- [#4929](https://github.com/statelyai/xstate/pull/4929) [`417f35a11`](https://github.com/statelyai/xstate/commit/417f35a119d2d5a579927af4a971a41857836b4a) Thanks [@boneskull](https://github.com/boneskull)! - Expose type `UnknownActorRef` for use when calling `getSnapshot()` on an unknown `ActorRef`.

## 5.13.2

### Patch Changes

- [#4932](https://github.com/statelyai/xstate/pull/4932) [`71a7f8692`](https://github.com/statelyai/xstate/commit/71a7f8692beabfea97d1741098cf406e66cf4b0b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Actors with emitted events should no longer cause type issues: https://github.com/statelyai/xstate/issues/4931

## 5.13.1

### Patch Changes

- [#4905](https://github.com/statelyai/xstate/pull/4905) [`dbeafeb25`](https://github.com/statelyai/xstate/commit/dbeafeb25eed63ee1d2b027f10bc63d9937ab073) Thanks [@davidkpiano](https://github.com/davidkpiano)! - You can now use a wildcard to listen for _any_ emitted event from an actor:

```ts
actor.on('*', (emitted) => {
console.log(emitted); // Any emitted event
});
```

## 5.13.0

### Minor Changes

- [#4832](https://github.com/statelyai/xstate/pull/4832) [`148d8fcef`](https://github.com/statelyai/xstate/commit/148d8fcef7f7467d05bbd427942a3668cb46afe7) Thanks [@cevr](https://github.com/cevr)! - `fromPromise` now passes a signal into its creator function.

```ts
const logic = fromPromise(({ signal }) =>
fetch('https://api.example.com', { signal })
);
```

This will be called whenever the state transitions before the promise is resolved. This is useful for cancelling the promise if the state changes.

### Patch Changes

- [#4876](https://github.com/statelyai/xstate/pull/4876) [`3f6a73b56`](https://github.com/statelyai/xstate/commit/3f6a73b56cb82b43897bc9d583483e0256dbc05c) Thanks [@davidkpiano](https://github.com/davidkpiano)! - XState will now warn when calling built-in actions like `assign`, `sendTo`, `raise`, `emit`, etc. directly inside of a custom action. See https://stately.ai/docs/actions#built-in-actions for more details.

```ts
const machine = createMachine({
entry: () => {
// Will warn:
// "Custom actions should not call \`assign()\` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details."
assign({
// ...
});
}
});
```

## 5.12.0

### Minor Changes

- [#4863](https://github.com/statelyai/xstate/pull/4863) [`0696adc21`](https://github.com/statelyai/xstate/commit/0696adc21d2e4c0a48ee3a5b0a8321a43f0e0d30) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Meta objects for state nodes and transitions can now be specified in `setup({ types: … })`:

```ts
const machine = setup({
types: {
meta: {} as {
layout: string;
}
}
}).createMachine({
initial: 'home',
states: {
home: {
meta: {
layout: 'full'
}
}
}
});

const actor = createActor(machine).start();

actor.getSnapshot().getMeta().home;
// => { layout: 'full' }
// if in "home" state
```

## 5.11.0

### Minor Changes

- [#4806](https://github.com/statelyai/xstate/pull/4806) [`f4e0ec48c`](https://github.com/statelyai/xstate/commit/f4e0ec48cccbbe3e74de8a6a5b25eaa727512a83) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Inline actor logic is now permitted when named actors are present. Defining inline actors will no longer cause a TypeScript error:

```ts
const machine = setup({
actors: {
existingActor: fromPromise(async () => {
// ...
})
}
}).createMachine({
invoke: {
src: fromPromise(async () => {
// Inline actor
})
// ...
}
});
```

## 5.10.0

### Minor Changes

- [#4822](https://github.com/statelyai/xstate/pull/4822) [`f7f1fbbf3`](https://github.com/statelyai/xstate/commit/f7f1fbbf3d56af9fcffe6ef9a37ab5953a90ca72) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `clock` and `logger` specified in the `options` object of `createActor(logic, options)` will now propagate to all actors created within the same actor system.

```ts
import { setup, log, createActor } from 'xstate';

const childMachine = setup({
// ...
}).createMachine({
// ...
// Uses custom logger from root actor
entry: log('something')
});

const parentMachine = setup({
// ...
}).createMachine({
// ...
invoke: {
src: childMachine
}
});

const actor = createActor(parentMachine, {
logger: (...args) => {
// custom logger for args
}
});

actor.start();
```

## 5.9.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xstate",
"version": "5.9.1",
"version": "5.14.0",
"description": "Finite State Machines and Statecharts for the Modern Web.",
"main": "dist/xstate.cjs.js",
"module": "dist/xstate.esm.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ interface MachineSnapshotBase<
TTag,
unknown,
TOutput,
EventObject // TEmitted
EventObject, // TEmitted
any // TMeta
>;
/**
* The tags of the active state nodes that represent the current state value.
Expand Down
32 changes: 29 additions & 3 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class StateMachine<
TInput,
TOutput,
TEmitted extends EventObject = EventObject, // TODO: remove default
TMeta extends MetaObject = MetaObject,
TResolvedTypesMeta = ResolveTypegenMeta<
TypegenDisabled,
DoNotInfer<TEvent>,
Expand Down Expand Up @@ -203,6 +204,7 @@ export class StateMachine<
TInput,
TOutput,
TEmitted,
TMeta, // TMeta
TResolvedTypesMeta
> {
const { actions, guards, actors, delays } = this.implementations;
Expand Down Expand Up @@ -283,7 +285,15 @@ export class StateMachine<
>,
event: TEvent,
actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>
): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput> {
): MachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TMeta
> {
return macrostep(snapshot, event, actorScope).snapshot as typeof snapshot;
}

Expand Down Expand Up @@ -385,7 +395,15 @@ export class StateMachine<
*/
public getInitialSnapshot(
actorScope: ActorScope<
MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>,
MachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TMeta
>,
TEvent,
AnyActorSystem,
TEmitted
Expand Down Expand Up @@ -497,7 +515,15 @@ export class StateMachine<
public restoreSnapshot(
snapshot: Snapshot<unknown>,
_actorScope: ActorScope<
MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>,
MachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TMeta
>,
TEvent,
AnyActorSystem,
TEmitted
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class StateNode<
any, // input
any, // output
any, // emitted
any, // TMeta
any // typegen
>;
/**
Expand Down Expand Up @@ -166,7 +167,8 @@ export class StateNode<
TODO, // delays
TODO, // tags
TODO, // output
TODO // emitted
TODO, // emitted
TODO // meta
>,
options: StateNodeOptions<TContext, TEvent>
) {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/actions/emit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isDevelopment from '#is-development';
import { executingCustomAction } from '../stateUtils.ts';
import {
ActionArgs,
AnyActorScope,
Expand Down Expand Up @@ -121,6 +122,12 @@ export function emit<
never,
TEmitted
> {
if (isDevelopment && executingCustomAction) {
console.warn(
'Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.'
);
}

function emit(
args: ActionArgs<TContext, TExpressionEvent, TEvent>,
params: TParams
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/actors/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ export type CallbackSnapshot<TInput> = Snapshot<undefined> & {

export type CallbackActorLogic<
TEvent extends EventObject,
TInput = NonReducibleUnknown
TInput = NonReducibleUnknown,
TEmitted extends EventObject = EventObject
> = ActorLogic<
CallbackSnapshot<TInput>,
TEvent,
TInput,
AnyActorSystem,
EventObject // TEmitted
TEmitted
>;

export type CallbackActorRef<
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actors/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type ObservableActorLogic<
{ type: string; [k: string]: unknown },
TInput,
AnyActorSystem,
EventObject // TEmitted
TEmitted
>;

export type ObservableActorRef<TContext> = ActorRefFrom<
Expand Down
Loading

0 comments on commit fdddbda

Please sign in to comment.