Skip to content

Commit

Permalink
Add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed May 14, 2021
1 parent d060b79 commit 28059b9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .changeset/neat-boxes-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'xstate': minor
---

All spawned and invoked actors now have a `.getSnapshot()` method, which allows you to retrieve the latest value emitted from that actor. That value may be `undefined` if no value has been emitted yet.

```js
const machine = createMachine({
context: {
promiseRef: null
},
initial: 'pending',
states: {
pending: {
entry: assign({
promiseRef: () => spawn(fetch(/* ... */), 'some-promise')
})
}
}
});

const service = interpret(machine)
.onTransition((state) => {
// Read promise value synchronously
const resolvedValue = state.context.promiseRef?.getSnapshot();
// => undefined (if promise not resolved yet)
// => { ... } (resolved data)
})
.start();

// ...
```

0 comments on commit 28059b9

Please sign in to comment.