diff --git a/.changeset/poor-bugs-reflect.md b/.changeset/poor-bugs-reflect.md deleted file mode 100644 index 2546ef770a..0000000000 --- a/.changeset/poor-bugs-reflect.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -'@xstate/graph': minor ---- - -Options passed into graph functions (e.g., `getShortestPaths(machine, options)`) can now resolve `.events` based on the `state`: - -```js -const countMachine = createMachine({ - initial: 'active', - context: { - count: 0 - }, - states: { - active: { - on: { - ADD: { - actions: assign({ - count: (context, event) => { - return context.count + event.value; - } - }) - } - } - } - } -}); - -const shortestPaths = getShortestPaths(countMachine, { - events: { - ADD: (state) => { - // contrived example: if `context.count` is >= 10, increment by 10 - return state.context.count >= 10 - ? [{ type: 'ADD', value: 10 }] - : [{ type: 'ADD', value: 1 }]; - } - } -}); - -// The keys to the shortest paths will look like: -// "active" | { count: 0 } -// "active" | { count: 1 } -// "active" | { count: 2 } -// ... -// "active" | { count: 10 } -// "active" | { count: 20 } -// "active" | { count: 30 } -``` diff --git a/packages/xstate-graph/CHANGELOG.md b/packages/xstate-graph/CHANGELOG.md index d77484f611..5964ac0fa6 100644 --- a/packages/xstate-graph/CHANGELOG.md +++ b/packages/xstate-graph/CHANGELOG.md @@ -1,5 +1,53 @@ # @xstate/graph +## 1.3.0 + +### Minor Changes + +- [`111a7d13`](https://github.com/davidkpiano/xstate/commit/111a7d138db909e969629a3c237b952850c008ca) [#1663](https://github.com/davidkpiano/xstate/pull/1663) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Options passed into graph functions (e.g., `getShortestPaths(machine, options)`) can now resolve `.events` based on the `state`: + + ```js + const countMachine = createMachine({ + initial: 'active', + context: { + count: 0 + }, + states: { + active: { + on: { + ADD: { + actions: assign({ + count: (context, event) => { + return context.count + event.value; + } + }) + } + } + } + } + }); + + const shortestPaths = getShortestPaths(countMachine, { + events: { + ADD: state => { + // contrived example: if `context.count` is >= 10, increment by 10 + return state.context.count >= 10 + ? [{ type: 'ADD', value: 10 }] + : [{ type: 'ADD', value: 1 }]; + } + } + }); + + // The keys to the shortest paths will look like: + // "active" | { count: 0 } + // "active" | { count: 1 } + // "active" | { count: 2 } + // ... + // "active" | { count: 10 } + // "active" | { count: 20 } + // "active" | { count: 30 } + ``` + ## 1.2.0 ### Minor Changes diff --git a/packages/xstate-graph/package.json b/packages/xstate-graph/package.json index e56c0a3e4c..8cbb0c337f 100644 --- a/packages/xstate-graph/package.json +++ b/packages/xstate-graph/package.json @@ -1,6 +1,6 @@ { "name": "@xstate/graph", - "version": "1.2.0", + "version": "1.3.0", "description": "XState graph utilities", "keywords": [ "state",