Skip to content

Commit

Permalink
Merge branch 'main' into davidkpiano/spawn-from-any-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Feb 9, 2024
2 parents a6f4f3e + 91549ce commit 352c3ce
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 49 deletions.
5 changes: 0 additions & 5 deletions .changeset/slow-swans-punch.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/stale-snails-drive.md

This file was deleted.

27 changes: 27 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# xstate

## 5.6.2

### Patch Changes

- [#4731](https://github.com/statelyai/xstate/pull/4731) [`960cdcbcb`](https://github.com/statelyai/xstate/commit/960cdcbcb88eb565bba2f03f3eeceff6001576d9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - You can now import `getInitialSnapshot(…)` from `xstate` directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) without `createActor(…)`:

```ts
import { getInitialSnapshot } from 'xstate';
import { someMachine } from './someMachine';

// Returns the initial snapshot (state) of the machine
const initialSnapshot = getInitialSnapshot(
someMachine,
{ name: 'Mateusz' } // optional input
);
```

## 5.6.1

### Patch Changes

- [#4728](https://github.com/statelyai/xstate/pull/4728) [`659efd5c1`](https://github.com/statelyai/xstate/commit/659efd5c14b69038b0c234255494c2fe5418fdea) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility issue of the internal type definitions with TypeScript 5.0

- [#4712](https://github.com/statelyai/xstate/pull/4712) [`2f1d36a9d`](https://github.com/statelyai/xstate/commit/2f1d36a9d949119bb93295362523de59acc039a0) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Ensure that `InteropObservable` and `InteropSubscribable` are present in the type definition file.

- [#4694](https://github.com/statelyai/xstate/pull/4694) [`0b6dff210`](https://github.com/statelyai/xstate/commit/0b6dff21069bb168b46c943653e445ff3daa5d63) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Add `UnknownMachineConfig` type

## 5.6.0

### Minor 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.6.0",
"version": "5.6.2",
"description": "Finite State Machines and Statecharts for the Modern Web.",
"main": "dist/xstate.cjs.js",
"module": "dist/xstate.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export * from './typegenTypes.ts';
export * from './types.ts';
export { waitFor } from './waitFor.ts';
import { createMachine } from './createMachine.ts';
export { getNextSnapshot } from './getNextSnapshot.ts';
export { getNextSnapshot, getInitialSnapshot } from './getNextSnapshot.ts';
import { Actor, createActor, interpret, Interpreter } from './createActor.ts';
import { StateNode } from './StateNode.ts';
// TODO: decide from where those should be exported
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ToProvidedActor<
id: IsNever<TChildrenMap> extends true
? string | undefined
: K extends keyof Invert<TChildrenMap>
? Invert<TChildrenMap>[K]
? Invert<TChildrenMap>[K] & string
: string | undefined;
};
}>;
Expand Down
26 changes: 14 additions & 12 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2352,19 +2352,21 @@ export type ToChildren<TActor extends ProvidedActor> =
// or maybe even `TActor["logic"]` since it's possible to configure `{ src: string; logic: SomeConcreteLogic }`
// TODO: consider adding `| undefined` here
Record<string, AnyActorRef>
: ToConcreteChildren<TActor> &
{
include: {
[id: string]: TActor extends any
? ActorRefFrom<TActor['logic']> | undefined
: never;
};
exclude: {};
}[undefined extends TActor['id'] // if not all actors have literal string IDs then we need to create an index signature containing all possible actor types
? 'include'
: string extends TActor['id']
: Compute<
ToConcreteChildren<TActor> &
{
include: {
[id: string]: TActor extends any
? ActorRefFrom<TActor['logic']> | undefined
: never;
};
exclude: {};
}[undefined extends TActor['id'] // if not all actors have literal string IDs then we need to create an index signature containing all possible actor types
? 'include'
: 'exclude'];
: string extends TActor['id']
? 'include'
: 'exclude']
>;

export type StateSchema = {
states?: Record<string, StateSchema>;
Expand Down
10 changes: 7 additions & 3 deletions packages/core/test/deterministic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { fromCallback, createActor, getNextSnapshot } from '../src/index.ts';
import { createMachine } from '../src/createMachine.ts';
import { getInitialSnapshot } from '../src/getNextSnapshot.ts';
import {
fromCallback,
createActor,
getNextSnapshot,
createMachine,
getInitialSnapshot
} from '../src/index.ts';

describe('deterministic machine', () => {
const lightMachine = createMachine({
Expand Down
5 changes: 2 additions & 3 deletions packages/core/test/getNextSnapshot.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
createActor,
createMachine,
fromTransition,
getNextSnapshot
getNextSnapshot,
getInitialSnapshot
} from '../src';
import { getInitialSnapshot } from '../src/getNextSnapshot';

describe('getNextSnapshot', () => {
it('should calculate the next snapshot for transition logic', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/core/test/id.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { testAll } from './utils';
import { createMachine, createActor } from '../src/index.ts';
import { getInitialSnapshot, getNextSnapshot } from '../src/getNextSnapshot.ts';
import {
createMachine,
createActor,
getNextSnapshot,
getInitialSnapshot
} from '../src/index.ts';

const idMachine = createMachine({
initial: 'A',
Expand Down
4 changes: 2 additions & 2 deletions packages/xstate-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"url": "https://github.com/statelyai/xstate/issues"
},
"peerDependencies": {
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"devDependencies": {
"xstate": "5.6.0"
"xstate": "5.6.2"
},
"dependencies": {}
}
4 changes: 2 additions & 2 deletions packages/xstate-immer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"dependencies": {},
"peerDependencies": {
"immer": "^9.0.6 || ^10",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"devDependencies": {
"immer": "^10.0.2",
"xstate": "5.6.0"
"xstate": "5.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/xstate-inspect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
"devDependencies": {
"@types/ws": "^8.2.2",
"ws": "^8.4.0",
"xstate": "5.6.0"
"xstate": "5.6.2"
},
"peerDependencies": {
"@types/ws": "^8.0.0",
"ws": "^8.0.0",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"peerDependenciesMeta": {
"@types/ws": {
Expand Down
4 changes: 2 additions & 2 deletions packages/xstate-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"peerDependenciesMeta": {
"xstate": {
Expand All @@ -76,6 +76,6 @@
"jsdom-global": "^3.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"xstate": "5.6.0"
"xstate": "5.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/xstate-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"peerDependencies": {
"solid-js": "^1.6.0",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"peerDependenciesMeta": {
"xstate": {
Expand All @@ -53,6 +53,6 @@
"devDependencies": {
"solid-js": "^1.7.6",
"solid-testing-library": "^0.3.0",
"xstate": "5.6.0"
"xstate": "5.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/xstate-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"peerDependencies": {
"svelte": "^3.24.1 || ^4",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"peerDependenciesMeta": {
"xstate": {
Expand All @@ -60,6 +60,6 @@
"svelte-check": "^3.2.0",
"svelte-jester": "^2.3.2",
"svelte-preprocess": "^5.0.0",
"xstate": "5.6.0"
"xstate": "5.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/xstate-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"url": "https://github.com/statelyai/xstate/issues"
},
"peerDependencies": {
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"devDependencies": {
"strip-ansi": "^5.2.0",
"xstate": "5.6.0"
"xstate": "5.6.2"
},
"dependencies": {
"@xstate/graph": "2.0.0-beta.6"
Expand Down
4 changes: 2 additions & 2 deletions packages/xstate-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"peerDependencies": {
"vue": "^3.0.0",
"xstate": "^5.6.0"
"xstate": "^5.6.2"
},
"peerDependenciesMeta": {
"xstate": {
Expand All @@ -66,6 +66,6 @@
"@testing-library/vue": "^6.6.1",
"@vue/compiler-sfc": "^3.0.11",
"vue": "^3.0.11",
"xstate": "5.6.0"
"xstate": "5.6.2"
}
}

0 comments on commit 352c3ce

Please sign in to comment.