Skip to content

Instantly share code, notes, and snippets.

@RafalFilipek
Created March 20, 2020 14:42
Show Gist options
  • Save RafalFilipek/88a9c6d378dd080e60a28fc68a57513b to your computer and use it in GitHub Desktop.
Save RafalFilipek/88a9c6d378dd080e60a28fc68a57513b to your computer and use it in GitHub Desktop.
import { createMachine, assign } from "xstate";
type Context = {
groups: number[],
group: number
}
type Event =
| { type: "SELECT_OFFER_GROUP"; data: number }
| { type: "SET_GROUPS"; data: number[] };
const m = createMachine<Context, Event>(
{ initial: "start" },
{
actions: {
/**
setGroups error:
Types of parameters 'event' and 'event' are incompatible.
Type 'Event' is not assignable to type '{ type: "SET_GROUPS"; data: number[]; }'.
Type '{ type: "SELECT_OFFER_GROUP"; data: number; }' is not assignable to type '{ type: "SET_GROUPS"; data: number[]; }'
*/
'setGroups': assign<Context, { type: "SET_GROUPS"; data: number[] }>({
groups: (c, e) => e.data
}),
'selectGroup': assign({
/**
e.data is (property) data: number | number[]
*/
group: (_, e) => e.data
})
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment