Skip to content

Commit 9841fab

Browse files
Version Packages (#4967)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 452bce7 commit 9841fab

File tree

11 files changed

+151
-153
lines changed

11 files changed

+151
-153
lines changed

.changeset/mighty-guests-hunt.md

Lines changed: 0 additions & 133 deletions
This file was deleted.

.changeset/six-crabs-hang.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/core/CHANGELOG.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,141 @@
11
# xstate
22

3+
## 5.15.0
4+
5+
### Minor Changes
6+
7+
- [#4976](https://github.com/statelyai/xstate/pull/4976) [`452bce71e`](https://github.com/statelyai/xstate/commit/452bce71e56fb28bfd85294b44138cf1bd5a9608) Thanks [@with-heart](https://github.com/with-heart)! - Added exports for actor logic-specific `ActorRef` types: `CallbackActorRef`, `ObservableActorRef`, `PromiseActorRef`, and `TransitionActorRef`.
8+
9+
Each type represents `ActorRef` narrowed to the corresponding type of logic (the type of `self` within the actor's logic):
10+
11+
- `CallbackActorRef`: actor created by [`fromCallback`](https://stately.ai/docs/actors#fromcallback)
12+
13+
```ts
14+
import { fromCallback, createActor } from 'xstate';
15+
16+
/** The events the actor receives. */
17+
type Event = { type: 'someEvent' };
18+
/** The actor's input. */
19+
type Input = { name: string };
20+
21+
/** Actor logic that logs whenever it receives an event of type `someEvent`. */
22+
const logic = fromCallback<Event, Input>(({ self, input, receive }) => {
23+
self;
24+
// ^? CallbackActorRef<Event, Input>
25+
26+
receive((event) => {
27+
if (event.type === 'someEvent') {
28+
console.log(`${input.name}: received "someEvent" event`);
29+
// logs 'myActor: received "someEvent" event'
30+
}
31+
});
32+
});
33+
34+
const actor = createActor(logic, { input: { name: 'myActor' } });
35+
// ^? CallbackActorRef<Event, Input>
36+
```
37+
38+
- `ObservableActorRef`: actor created by [`fromObservable`](https://stately.ai/docs/actors#fromobservable) and [`fromEventObservable`](https://stately.ai/docs/actors#fromeventobservable)
39+
40+
```ts
41+
import { fromObservable, createActor } from 'xstate';
42+
import { interval } from 'rxjs';
43+
44+
/** The type of the value observed by the actor's logic. */
45+
type Context = number;
46+
/** The actor's input. */
47+
type Input = { period?: number };
48+
49+
/**
50+
* Actor logic that observes a number incremented every `input.period`
51+
* milliseconds (default: 1_000).
52+
*/
53+
const logic = fromObservable<Context, Input>(({ input, self }) => {
54+
self;
55+
// ^? ObservableActorRef<Event, Input>
56+
57+
return interval(input.period ?? 1_000);
58+
});
59+
60+
const actor = createActor(logic, { input: { period: 2_000 } });
61+
// ^? ObservableActorRef<Event, Input>
62+
```
63+
64+
- `PromiseActorRef`: actor created by [`fromPromise`](https://stately.ai/docs/actors#actors-as-promises)
65+
66+
```ts
67+
import { fromPromise, createActor } from 'xstate';
68+
69+
/** The actor's resolved output. */
70+
type Output = string;
71+
/** The actor's input. */
72+
type Input = { message: string };
73+
74+
/** Actor logic that fetches the url of an image of a cat saying `input.message`. */
75+
const logic = fromPromise<Output, Input>(async ({ input, self }) => {
76+
self;
77+
// ^? PromiseActorRef<Output, Input>
78+
79+
const data = await fetch(`https://cataas.com/cat/says/${input.message}`);
80+
const url = await data.json();
81+
return url;
82+
});
83+
84+
const actor = createActor(logic, { input: { message: 'hello world' } });
85+
// ^? PromiseActorRef<Output, Input>
86+
```
87+
88+
- `TransitionActorRef`: actor created by [`fromTransition`](https://stately.ai/docs/actors#fromtransition)
89+
90+
```ts
91+
import { fromTransition, createActor, type AnyActorSystem } from 'xstate';
92+
93+
/** The actor's stored context. */
94+
type Context = {
95+
/** The current count. */
96+
count: number;
97+
/** The amount to increase `count` by. */
98+
step: number;
99+
};
100+
/** The events the actor receives. */
101+
type Event = { type: 'increment' };
102+
/** The actor's input. */
103+
type Input = { step?: number };
104+
105+
/**
106+
* Actor logic that increments `count` by `step` when it receives an event of
107+
* type `increment`.
108+
*/
109+
const logic = fromTransition<Context, Event, AnyActorSystem, Input>(
110+
(state, event, actorScope) => {
111+
actorScope.self;
112+
// ^? TransitionActorRef<Context, Event>
113+
114+
if (event.type === 'increment') {
115+
return {
116+
...state,
117+
count: state.count + state.step
118+
};
119+
}
120+
return state;
121+
},
122+
({ input, self }) => {
123+
self;
124+
// ^? TransitionActorRef<Context, Event>
125+
126+
return {
127+
count: 0,
128+
step: input.step ?? 1
129+
};
130+
}
131+
);
132+
133+
const actor = createActor(logic, { input: { step: 10 } });
134+
// ^? TransitionActorRef<Context, Event>
135+
```
136+
137+
- [#4949](https://github.com/statelyai/xstate/pull/4949) [`8aa4c2b90`](https://github.com/statelyai/xstate/commit/8aa4c2b90c6a07a4678202181420b5ddd33edacf) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The TypeGen-related types have been removed from XState, simplifying the internal types without affecting normal XState usage.
138+
3139
## 5.14.0
4140
5141
### Minor Changes

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xstate",
3-
"version": "5.14.0",
3+
"version": "5.15.0",
44
"description": "Finite State Machines and Statecharts for the Modern Web.",
55
"main": "dist/xstate.cjs.js",
66
"module": "dist/xstate.esm.js",

packages/xstate-graph/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
"url": "https://github.com/statelyai/xstate/issues"
4141
},
4242
"peerDependencies": {
43-
"xstate": "^5.14.0"
43+
"xstate": "^5.15.0"
4444
},
4545
"devDependencies": {
46-
"xstate": "5.14.0"
46+
"xstate": "5.15.0"
4747
},
4848
"dependencies": {}
4949
}

packages/xstate-immer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
"dependencies": {},
4242
"peerDependencies": {
4343
"immer": "^9.0.6 || ^10",
44-
"xstate": "^5.14.0"
44+
"xstate": "^5.15.0"
4545
},
4646
"devDependencies": {
4747
"immer": "^10.0.2",
48-
"xstate": "5.14.0"
48+
"xstate": "5.15.0"
4949
}
5050
}

packages/xstate-inspect/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
"devDependencies": {
5454
"@types/ws": "^8.2.2",
5555
"ws": "^8.4.0",
56-
"xstate": "5.14.0"
56+
"xstate": "5.15.0"
5757
},
5858
"peerDependencies": {
5959
"@types/ws": "^8.0.0",
6060
"ws": "^8.0.0",
61-
"xstate": "^5.14.0"
61+
"xstate": "^5.15.0"
6262
},
6363
"peerDependenciesMeta": {
6464
"@types/ws": {

packages/xstate-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"peerDependencies": {
5757
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
58-
"xstate": "^5.14.0"
58+
"xstate": "^5.15.0"
5959
},
6060
"peerDependenciesMeta": {
6161
"xstate": {
@@ -76,6 +76,6 @@
7676
"jsdom-global": "^3.0.2",
7777
"react": "^18.0.0",
7878
"react-dom": "^18.0.0",
79-
"xstate": "5.14.0"
79+
"xstate": "5.15.0"
8080
}
8181
}

packages/xstate-solid/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"peerDependencies": {
4545
"solid-js": "^1.6.0",
46-
"xstate": "^5.14.0"
46+
"xstate": "^5.15.0"
4747
},
4848
"peerDependenciesMeta": {
4949
"xstate": {
@@ -53,6 +53,6 @@
5353
"devDependencies": {
5454
"solid-js": "^1.7.6",
5555
"solid-testing-library": "^0.3.0",
56-
"xstate": "5.14.0"
56+
"xstate": "5.15.0"
5757
}
5858
}

packages/xstate-svelte/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"peerDependencies": {
4747
"svelte": "^3.24.1 || ^4",
48-
"xstate": "^5.14.0"
48+
"xstate": "^5.15.0"
4949
},
5050
"peerDependenciesMeta": {
5151
"xstate": {
@@ -60,6 +60,6 @@
6060
"svelte-check": "^3.2.0",
6161
"svelte-jester": "^2.3.2",
6262
"svelte-preprocess": "^5.0.0",
63-
"xstate": "5.14.0"
63+
"xstate": "5.15.0"
6464
}
6565
}

0 commit comments

Comments
 (0)