|
1 | 1 | # @xstate/store |
2 | 2 |
|
| 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 | + |
3 | 125 | ## 3.7.0 |
4 | 126 |
|
5 | 127 | ### Minor Changes |
|
76 | 198 | ### Minor Changes |
77 | 199 |
|
78 | 200 | - [#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 | | - |
80 | 201 | - Optimized recomputation logic to prevent unnecessary updates |
81 | 202 | - Added support for custom equality functions through `compare` option in `createAtom`, allowing fine-grained control over when atoms update: |
82 | 203 |
|
|
129 | 250 | ### Minor Changes |
130 | 251 |
|
131 | 252 | - [#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 | | - |
133 | 253 | - Create simple atoms with initial values: |
134 | 254 |
|
135 | 255 | ```ts |
|
200 | 320 | ### Minor Changes |
201 | 321 |
|
202 | 322 | - [#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 | | - |
204 | 323 | - `store.select(selector)` function to create a "selector" entity where you can: |
205 | 324 | - Get current value with `.get()` |
206 | 325 | - Subscribe to changes with `.subscribe(callback)` |
|
0 commit comments