Skip to content

Commit

Permalink
Add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Mar 17, 2021
1 parent 9aeb9e0 commit 5febfe8
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .changeset/fair-lemons-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
'xstate': minor
---

Event creators can now be modeled inside of the 2nd argument of `createModel()`, and types for both `context` and `events` will be inferred properly in `createMachine()` when given the `typeof model` as the first generic parameter.

```ts
import { createModel } from 'xstate/lib/model';

const userModel = createModel(
// initial context
{
name: 'David',
age: 30
},
// creators (just events for now)
{
events: {
updateName: (value: string) => ({ value }),
updateAge: (value: number) => ({ value }),
anotherEvent: () => ({}) // no payload
}
}
);

const machine = createMachine<typeof userModel>({
context: userModel.initialContext,
initial: 'active',
states: {
active: {
on: {
updateName: {
/* ... */
},
updateAge: {
/* ... */
}
}
}
}
});

const nextState = machine.transition(
undefined,
userModel.events.updateName('David')
);
```

0 comments on commit 5febfe8

Please sign in to comment.