2021-03-23 16:04:53 +01:00
|
|
|
import { createMachine } from "xstate";
|
2020-01-23 19:24:35 +01:00
|
|
|
|
2022-08-26 14:51:01 +02:00
|
|
|
type ToggleContext = {
|
|
|
|
value: "inactive" | "active";
|
|
|
|
};
|
|
|
|
|
|
|
|
type ToggleEvents = {
|
|
|
|
type: "TOGGLE";
|
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleMachine = createMachine<ToggleContext, ToggleEvents>({
|
|
|
|
predictableActionArguments: true,
|
2020-01-23 19:24:35 +01:00
|
|
|
id: "toggle",
|
|
|
|
initial: "inactive",
|
|
|
|
states: {
|
|
|
|
inactive: {
|
|
|
|
on: { TOGGLE: "active" },
|
|
|
|
},
|
|
|
|
active: {
|
|
|
|
on: { TOGGLE: "inactive" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|