Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Nwamba christiannwamba

View GitHub Profile
View pycon_music.json
{
"link": "djcb.link/cwg",
"name": "Christian Nwamba",
"twitter": "https://twitter.com/codebeast",
"bio": "Senior Cloud Advocate @ Microsoft",
"title": "DJ Coding",
"prerequisites": [
{"Sonic Pi": "https://sonic-pi.net/"},
{"VS Code": "https://code.visualstudio.com/"}
],
View zurish_serverless_days.json
{
"link": "djcb.link/t3s",
"name": "Christian Nwamba",
"twitter": "https://twitter.com/codebeast",
"bio": "Senior Cloud Advocate @ Microsoft",
"title": "Building Schedulers with Durable Functions",
"prerequisites": [
{"VS Code": "https://code.visualstudio.com/"},
{"Node.js": "https://nodejs.org/"},
{"Azure Functions Core Tools": "https://github.com/Azure/azure-functions-core-tools"},
View machine.js
// DEMO: Call events in child machines
// NOTE: Child machine viz is not supported yet
const childMachine = Machine({
id: 'child',
initial: 'step1',
states: {
step1: {
on: { STEP: 'step2' },
View machine.js
// DEMO: Call events anywhere (including parent machines/states) with callbacks
const echoCallbackHandler = (context, event) =>
(callback, onEvent) => {
onEvent(e => {
if(e.type === 'HEAR') {
callback('ECHO')
}
})
}
View machine.js
// DEMO: Async and Promises
const fetchCuteAnimals = () => {
// Uncomment to test failure
// return Promise.reject()
return fetch('https://www.reddit.com/r/aww.json')
.then(res => res.json())
.then(data => data.data.children.map(child => child.data))
}
View machine.js
//DEMO: Delay Events and
// Use after instead of `on` for timer events
const states = {
green: {
after: {
RED_TIMER: 'yellow'
}
},
View machine.js
// DEMO: Null or Transient Transitions with ''
// Cick TRY 3 times and it will get to success but will keep coming back to idle at 1 and 2 time
// You can see the state increment in the STATE tab when you click TRY
const ifAtFirstYouDontSucceed = Machine(
{
id: 'tryTryAgain',
initial: 'idle',
context: {
tries: 0,
View machine.js
// DEMO: History State Deep
const heatedStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
}
}
View machine.js
// DEMO: History State (Shallow)
const poweredOnStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
},
View machine.js
// DEMO: Guarding
const vendingMachineMachine = Machine(
{
id: "vendingMachine",
initial: "idle",
context: {
deposited: 0
},
states: {
You can’t perform that action at this time.