Skip to content

Instantly share code, notes, and snippets.

@jinnkhan88
jinnkhan88 / machine.js
Last active June 4, 2021 20:29
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: "lightBulbMachine",
initial: "unlit",
states: {
unlit: {
on: {
BREAK:'broken',
TOOGLE: "lit"
}
@jinnkhan88
jinnkhan88 / machine.js
Last active June 4, 2021 20:45
Generated by XState Viz: https://xstate.js.org/viz
const EchoMachine = Machine({
id:'echo',
initial:'listening',
states:{
listening:{
on:{
SPEAK:{
actions:send({type:'ECHO'})
},
ECHO:{
const multiColor = Machine({
id: "multiColor",
initial: "unlit",
context:{
color:'#000'
},
states: {
unlit: {
on: {
BREAK: "broken",
const VendingMachine = Machine({
id:'vendingMachine',
initial:'idle',
context:{
deposited:0
},
states:{
idle:{
on:{
SELECT_ITEM:{
const doorMachine = Machine({
id:'door',
initial:'locked',
states:{
locked:{
id:'locked',
on:{
unlocked:'unlocked'
}
},
const spaceHeader = Machine({
id:'spaceHeader',
initial:'poweredOff',
states:{
poweredOff:{
on:{
TOOGLE_POWER:'poweredOn'
}
},
poweredOn:{
@jinnkhan88
jinnkhan88 / machine.js
Last active June 6, 2021 18:52
Generated by XState Viz: https://xstate.js.org/viz
const spaceHeaterMachine = Machine({
id: 'spaceHeater',
initial: 'poweredOff',
states: {
poweredOff: {
on: { TOGGLE_POWER: 'poweredOn.hist' }
},
poweredOn: {
on: { TOGGLE_POWER: 'poweredOff' },
type:'parallel',
const tryAgainMachine = Machine({
id:'tryTryagain',
initial:'idle',
context:{
tries:0
},
states:{
idle:{
on:{ TRY:'trying'}
},
const lightMachine = Machine({
id:'trafficLight',
initial:'red',
context:{
rushHourMultiplier:1
},
on:{
INC_RUSH_HOUR:{
actions:['incRushHour']
const fetchAnimals = ()=>{
return fetch('https://www.reddit.com/r/aww.json')
.then(res => res.json())
.then(data => data.data.children.map(child => child.data))
}
const cuteAnimals = Machine({
id:'cuteAnimals',
initial:'idle',
context:{