Skip to content

Instantly share code, notes, and snippets.

View christiannwamba's full-sized avatar

Christian Nwamba christiannwamba

  • AWS
  • Lagos, Nigeria
View GitHub Profile
{
"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/"}
],
{
"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"},
// 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' },
// DEMO: Call events anywhere (including parent machines/states) with callbacks
const echoCallbackHandler = (context, event) =>
(callback, onEvent) => {
onEvent(e => {
if(e.type === 'HEAR') {
callback('ECHO')
}
})
}
// 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))
}
//DEMO: Delay Events and
// Use after instead of `on` for timer events
const states = {
green: {
after: {
RED_TIMER: 'yellow'
}
},
// 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,
// DEMO: History State Deep
const heatedStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
}
}
// DEMO: History State (Shallow)
const poweredOnStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
},
// DEMO: Guarding
const vendingMachineMachine = Machine(
{
id: "vendingMachine",
initial: "idle",
context: {
deposited: 0
},
states: {