import { actions, assign, interpret, Machine } from "https://[Log in to view URL]"
const { choose, log } = actions
const toggleMachine = Machine({
id: "toggle",
initial: "inactive",
states: {
inactive: { on: { TOGGLE: "active" } },
active: { on: { TOGGLE: "inactive" } },
},
});
// Machine instance with internal state
const toggleService = interpret(toggleMachine)
.onTransition((state: any) => console.log(state.value))
.start();
// => 'inactive'
toggleService.send("TOGGLE");
// => 'active'
toggleService.send("TOGGLE");
// => 'inactive'
//src: https://[Log in to view URL]
const chooseMachine = Machine(
{
context: {},
initial: 'foo',
states: {
foo: {
entry: 'conditionallyRevealAnswer'
}
}
},
{
guards: {
worstGuard: () => true
},
actions: {
revealAnswer: assign({ answer: 42 }),
conditionallyRevealAnswer: choose([
{ cond: 'worstGuard', actions: 'revealAnswer' }
])
}
}
);
const chooseService = interpret(chooseMachine)
.onTransition((state: any) => console.log(state.context))
.start()
// { answer: 42 }
To embed this project on your website, copy the following code and paste it into your website's HTML: