Skip to content

Commit 5ba73cb

Browse files
authored
Merge branch 'statelyai:main' into actor-select
2 parents e1f2808 + 12b4437 commit 5ba73cb

File tree

19 files changed

+4207
-3372
lines changed

19 files changed

+4207
-3372
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@
8888
8989
}
9090
},
91-
"packageManager": "pnpm@9.7.1+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247"
91+
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
9292
}

packages/core/CHANGELOG.md

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

3+
## 5.20.1
4+
5+
### Patch Changes
6+
7+
- [#5315](https://github.com/statelyai/xstate/pull/5315) [`9a0ae82`](https://github.com/statelyai/xstate/commit/9a0ae82d460131d864be4deafeaffc18b42d3bda) Thanks [@sfc-gh-dperezalvarez](https://github.com/sfc-gh-dperezalvarez)! - Exported `InspectedActionEvent` type
8+
39
## 5.20.0
410

511
### 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.20.0",
3+
"version": "5.20.1",
44
"description": "Finite State Machines and Statecharts for the Modern Web.",
55
"main": "dist/xstate.cjs.js",
66
"module": "dist/xstate.esm.js",

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export { createMachine } from './createMachine.ts';
1212
export { getInitialSnapshot, getNextSnapshot } from './getNextSnapshot.ts';
1313
export { and, not, or, stateIn } from './guards.ts';
1414
export type {
15+
InspectedActionEvent,
1516
InspectedActorEvent,
1617
InspectedEventEvent,
18+
InspectedMicrostepEvent,
1719
InspectedSnapshotEvent,
1820
InspectionEvent
1921
} from './inspection.ts';

packages/core/src/inspection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface InspectedSnapshotEvent extends BaseInspectionEventProperties {
3030
snapshot: Snapshot<unknown>;
3131
}
3232

33-
interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
33+
export interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
3434
type: '@xstate.microstep';
3535
event: AnyEventObject; // { type: string, ... }
3636
snapshot: Snapshot<unknown>;

packages/xstate-store/CHANGELOG.md

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,127 @@
11
# @xstate/store
22

3+
## 3.8.4
4+
5+
### Patch Changes
6+
7+
- [#5337](https://github.com/statelyai/xstate/pull/5337) [`b64a6c9`](https://github.com/statelyai/xstate/commit/b64a6c925d87bce6246d35e562bdda6907e2e33f) Thanks [@flbn](https://github.com/flbn)! - chore: add missing EventFromStoreConfig, EmitsFromStoreConfig, ContextFromStoreConfig types from @xstate/store exports
8+
9+
## 3.8.3
10+
11+
### Patch Changes
12+
13+
- [#5334](https://github.com/statelyai/xstate/pull/5334) [`c4adf25`](https://github.com/statelyai/xstate/commit/c4adf25331faeb15004d449b35799c53bd069b1b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `createStore` function now supports explicit generic type parameters for better type control when needed. This allows you to specify the exact types for context, events, and emitted events instead of relying solely on type inference if desired.
14+
15+
```ts
16+
type CoffeeContext = {
17+
beans: number;
18+
cups: number;
19+
};
20+
21+
type CoffeeEvents =
22+
| { type: 'addBeans'; amount: number }
23+
| { type: 'brewCup' };
24+
25+
type CoffeeEmitted =
26+
| { type: 'beansAdded'; amount: number }
27+
| { type: 'cupBrewed' };
28+
29+
const coffeeStore = createStore<CoffeeContext, CoffeeEvents, CoffeeEmitted>({
30+
context: {
31+
beans: 0,
32+
cups: 0
33+
},
34+
on: {
35+
addBeans: (ctx, event, enq) => {
36+
enq.emit.beansAdded({ amount: event.amount });
37+
return { ...ctx, beans: ctx.beans + event.amount };
38+
},
39+
brewCup: (ctx, _, enq) => {
40+
if (ctx.beans > 0) {
41+
enq.emit.cupBrewed();
42+
return { ...ctx, beans: ctx.beans - 1, cups: ctx.cups + 1 };
43+
}
44+
45+
return ctx;
46+
}
47+
}
48+
});
49+
```
50+
51+
## 3.8.2
52+
53+
### Patch Changes
54+
55+
- [#5329](https://github.com/statelyai/xstate/pull/5329) [`8a27bc4`](https://github.com/statelyai/xstate/commit/8a27bc43f975b03dc82a7e381a3956af49fb0633) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Fix: `createAsyncAtom` now properly propagates status updates after promise resolves/rejects.
56+
57+
## 3.8.1
58+
59+
### Patch Changes
60+
61+
- [#5326](https://github.com/statelyai/xstate/pull/5326) [`68ab6fb`](https://github.com/statelyai/xstate/commit/68ab6fb72d20c5bd2eb8d1d6249dc3046da79010) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The XState Store undo/redo package can now be imported as `@xstate/store/undo`.
62+
63+
```ts
64+
import { createStore } from '@xstate/store';
65+
import { undoRedo } from '@xstate/store/undo';
66+
67+
const store = createStore(
68+
undoRedo({
69+
context: {
70+
count: 0
71+
},
72+
on: {
73+
// ...
74+
}
75+
})
76+
);
77+
78+
// ...
79+
```
80+
81+
## 3.8.0
82+
83+
### Minor Changes
84+
85+
- [#5305](https://github.com/statelyai/xstate/pull/5305) [`725530f`](https://github.com/statelyai/xstate/commit/725530fd462c4300319fad82efc545ff44cf3e22) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Added undo/redo functionality to XState Store via the `undoRedo` higher-order store logic:
86+
- Adds `undo` and `redo` events to stores
87+
- Supports grouping related events into transactions using `transactionId`
88+
- Maintains event history for precise state reconstruction
89+
- Automatically clears redo stack when new events occur
90+
91+
```ts
92+
import { createStore } from '@xstate/store';
93+
import { undoRedo } from '@xstate/store/undo';
94+
95+
const store = createStore(
96+
undoRedo({
97+
context: { count: 0 },
98+
on: {
99+
inc: (ctx) => ({ count: ctx.count + 1 }),
100+
dec: (ctx) => ({ count: ctx.count - 1 })
101+
}
102+
})
103+
);
104+
105+
store.trigger.inc();
106+
// count: 1
107+
store.trigger.inc();
108+
// count: 2
109+
store.trigger.undo();
110+
// count: 1
111+
store.trigger.undo();
112+
// count: 0
113+
store.trigger.redo();
114+
// count: 1
115+
store.trigger.redo();
116+
// count: 2
117+
```
118+
119+
## 3.7.1
120+
121+
### Patch Changes
122+
123+
- [#5307](https://github.com/statelyai/xstate/pull/5307) [`b269485`](https://github.com/statelyai/xstate/commit/b269485e47b95fa57bbc75e34352f107ef2c37c3) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Fix the types for `useAtom` to accept `ReadonlyAtom` values.
124+
3125
## 3.7.0
4126

5127
### Minor Changes
@@ -76,7 +198,6 @@
76198
### Minor Changes
77199

78200
- [#5250](https://github.com/statelyai/xstate/pull/5250) [`a1bffb55b2029bde82e542d5936c51d961909a37`](https://github.com/statelyai/xstate/commit/a1bffb55b2029bde82e542d5936c51d961909a37) Thanks [@davidkpiano](https://github.com/davidkpiano)! - - Improved atom architecture with better dependency management (the diamond problem is solved!)
79-
80201
- Optimized recomputation logic to prevent unnecessary updates
81202
- Added support for custom equality functions through `compare` option in `createAtom`, allowing fine-grained control over when atoms update:
82203

@@ -129,7 +250,6 @@
129250
### Minor Changes
130251

131252
- [#5221](https://github.com/statelyai/xstate/pull/5221) [`4635d3d8d3debcfeef5cddd78613e32891c10eac`](https://github.com/statelyai/xstate/commit/4635d3d8d3debcfeef5cddd78613e32891c10eac) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Added `createAtom()` for creating reactive atoms that can be combined with other atoms and stores:
132-
133253
- Create simple atoms with initial values:
134254

135255
```ts
@@ -200,7 +320,6 @@
200320
### Minor Changes
201321

202322
- [#5200](https://github.com/statelyai/xstate/pull/5200) [`0332a16a42fb372eb614df74ff4cb7f003c31fc8`](https://github.com/statelyai/xstate/commit/0332a16a42fb372eb614df74ff4cb7f003c31fc8) Thanks [@{](https://github.com/{)! - Added selectors to @xstate/store that enable efficient state selection and subscription:
203-
204323
- `store.select(selector)` function to create a "selector" entity where you can:
205324
- Get current value with `.get()`
206325
- Subscribe to changes with `.subscribe(callback)`

packages/xstate-store/package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xstate/store",
3-
"version": "3.7.0",
3+
"version": "3.8.4",
44
"description": "Simple stores",
55
"keywords": [
66
"store",
@@ -12,6 +12,15 @@
1212
"main": "dist/xstate-store.cjs.js",
1313
"module": "dist/xstate-store.esm.js",
1414
"exports": {
15+
"./undo": {
16+
"types": {
17+
"import": "./undo/dist/xstate-store-undo.cjs.mjs",
18+
"default": "./undo/dist/xstate-store-undo.cjs.js"
19+
},
20+
"module": "./undo/dist/xstate-store-undo.esm.js",
21+
"import": "./undo/dist/xstate-store-undo.cjs.mjs",
22+
"default": "./undo/dist/xstate-store-undo.cjs.js"
23+
},
1524
".": {
1625
"types": {
1726
"import": "./dist/xstate-store.cjs.mjs",
@@ -45,7 +54,8 @@
4554
"files": [
4655
"dist",
4756
"react",
48-
"solid"
57+
"solid",
58+
"undo"
4959
],
5060
"repository": {
5161
"type": "git",
@@ -89,7 +99,8 @@
8999
"entrypoints": [
90100
"./index.ts",
91101
"./react.ts",
92-
"./solid.ts"
102+
"./solid.ts",
103+
"./undo.ts"
93104
]
94105
}
95106
}

packages/xstate-store/src/atom.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,24 @@ export function createAsyncAtom<T>(
6868
const atom = createAtom<AsyncAtomState<T>>(() => {
6969
getValue().then(
7070
(data) => {
71-
atom._update({ status: 'done', data });
71+
if (atom._update({ status: 'done', data })) {
72+
const subs = atom._subs;
73+
if (subs !== undefined) {
74+
propagate(subs);
75+
shallowPropagate(subs);
76+
flush();
77+
}
78+
}
7279
},
7380
(error) => {
74-
atom._update({ status: 'error', error });
81+
if (atom._update({ status: 'error', error })) {
82+
const subs = atom._subs;
83+
if (subs !== undefined) {
84+
propagate(subs);
85+
shallowPropagate(subs);
86+
flush();
87+
}
88+
}
7589
}
7690
);
7791

packages/xstate-store/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@ export type {
3434
Atom,
3535
AtomOptions,
3636
AnyAtom,
37-
ReadonlyAtom
37+
ReadonlyAtom,
38+
EventFromStoreConfig,
39+
EmitsFromStoreConfig,
40+
ContextFromStoreConfig
3841
} from './types';

packages/xstate-store/src/react.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ExtractEvents,
99
Readable,
1010
AnyAtom,
11-
Atom
11+
BaseAtom
1212
} from './types';
1313
import { createStore } from './store';
1414

@@ -128,9 +128,9 @@ export const useStore: {
128128
* @param compare An optional function which compares the selected value to the
129129
* previous value
130130
*/
131-
export function useAtom<T>(atom: Atom<T>): T;
131+
export function useAtom<T>(atom: BaseAtom<T>): T;
132132
export function useAtom<T, S>(
133-
atom: Atom<T>,
133+
atom: BaseAtom<T>,
134134
selector: (snapshot: T) => S,
135135
compare?: (a: S, b: S) => boolean
136136
): S;

0 commit comments

Comments
 (0)