Created
March 20, 2020 14:42
-
-
Save RafalFilipek/88a9c6d378dd080e60a28fc68a57513b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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