Last active
April 11, 2020 16:18
-
-
Save arbaaz/4f033d2dcceb188bdbafb71446f6118a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
const timeOfDayMachine = Machine({ | |
id: 'psm', | |
initial: 'namaz', | |
context: { | |
time: new Date(Date.now()) | |
}, | |
on: { | |
Root_Mode: { | |
actions: assign({ level: 'root' }) | |
}, | |
Start_Work: [{ target: 'work' }], | |
}, | |
states: { | |
namaz: { | |
type: 'compound', | |
initial: 'dawn', | |
onDone: 'dinner', | |
states: { | |
dawn: { | |
on: { | |
'': [ | |
{ target: 'fajr', cond: 'isFajr' }, | |
{ target: 'zohar', cond: 'isZohar' }, | |
{ target: 'asar', cond: 'isAsar' }, | |
{ target: 'maghrib', cond: 'isMaghrib' }, | |
{ target: 'isha', cond: 'isIsha' } | |
] | |
} | |
}, | |
fajr: { | |
on: { | |
NEXT: '#psm.work' | |
} | |
}, | |
zohar: { | |
on: { | |
NEXT: 'asar' | |
} | |
}, | |
asar: { | |
on: { | |
NEXT: 'maghrib' | |
} | |
}, | |
maghrib: { | |
on: { | |
NEXT: 'isha' | |
} | |
}, | |
isha: { | |
on: { | |
NEXT: 'done' | |
}, | |
}, | |
done: { | |
type: 'final' | |
} | |
}, | |
}, | |
breakfast: { | |
on: { | |
NEXT: 'work' | |
} | |
}, | |
work: { | |
meta: { | |
message: 'The request failed.' | |
}, | |
on: { | |
FIRST_BREAK: 'namaz.zohar', | |
SECOND_BREAK: 'namaz.asar' | |
} | |
}, | |
dinner: { | |
on: { | |
NEXT: 'quran' | |
}, | |
}, | |
quran: { | |
type: 'compound', | |
initial: 'pending', | |
states: { | |
pending: { | |
on: { | |
NEXT: 'read' | |
} | |
}, | |
read: { | |
on: { | |
NEXT: 'sleep' | |
} | |
}, | |
sleep: { | |
type: 'final' | |
} | |
}, | |
} | |
} | |
}, { | |
guards: { | |
isFajr: (context) => { | |
return context.time.getHours() < 6; | |
}, | |
isZohar: (context) => { | |
return context.time.getHours() > 12 && context.time.getHours() < 16; | |
}, | |
isAsar: (context) => { | |
return context.time.getHours() > 16 && context.time.getHours() < 18; | |
}, | |
isMaghrib: (context) => { | |
return context.time.getHours() > 18 && context.time.getHours() < 19; | |
}, | |
isIsha: (context) => { | |
return context.time.getHours() >= 19; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment