Skip to content

Instantly share code, notes, and snippets.

@kandros
Last active July 3, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kandros/4ef4896cbe1db32d2ffd092466eeac8f to your computer and use it in GitHub Desktop.
Save kandros/4ef4896cbe1db32d2ffd092466eeac8f to your computer and use it in GitHub Desktop.
Working Software
const paymentMachine = Machine({
id: 'payment',
initial: 'method',
states: {
method: {
initial: 'cash',
states: {
cash: { on: { SWITCH_CHECK: 'check' } },
check: { on: { SWITCH_CASH: 'cash' } },
hist: { type: 'history' }
},
on: { NEXT: 'review' }
},
review: {
on: { PREVIOUS: 'method.hist' }
}
}
});
https://hasura-demo-postgres.herokuapp.com/console/api-explorer
```
{
clients(where: {id: {
_eq: 1
}}){
name
}
}
```
// aggregato della somma di tutti i budget per ogni cliente
```
{
clients {
name
projects_aggregate {
aggregate {
sum {
budget
}
}
}
}
}
```
per ogni client
sum e average of his projects
```
{
clients {
name
projects {
name
budget
}
projects_aggregate {
aggregate {
avg {
budget
}
sum {
budget
}
}
}
}
}
```
const stepMachine = Machine({
id: 'step',
initial: 'one',
states: {
one: {
on: { NEXT: 'two' }
},
two: {
on: { NEXT: 'three', PREV: 'one' }
},
three: {
on: { PREV: 'two' }
}
}
});
const timeoutMachine = Machine({
initial: 'idle',
strict: true,
states: {
idle: {
on: { ACTIVITY: 'idle' },
after: { 3000: 'timeout' },
},
timeout: {
on: { ACTIVITY: 'idle' },
},
},
});
const lightMachine = Machine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
}
}
}
});
const pedestrianStates = {
initial: 'walk',
states: {
walk: {
on: {
PED_TIMER: 'wait'
}
},
wait: {
on: {
PED_TIMER: 'stop'
}
},
stop: {}
}
};
const lightMachine = Machine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
},
...pedestrianStates
}
}
});
const wordMachine = Machine({
id: 'word',
type: 'parallel',
states: {
bold: {
initial: 'off',
states: {
on: {
on: { TOGGLE_BOLD: 'off' }
},
off: {
on: { TOGGLE_BOLD: 'on' }
}
}
},
underline: {
initial: 'off',
states: {
on: {
on: { TOGGLE_UNDERLINE: 'off' }
},
off: {
on: { TOGGLE_UNDERLINE: 'on' }
}
}
},
italics: {
initial: 'off',
states: {
on: {
on: { TOGGLE_ITALICS: 'off' }
},
off: {
on: { TOGGLE_ITALICS: 'on' }
}
}
},
list: {
initial: 'none',
states: {
none: {
on: { BULLETS: 'bullets', NUMBERS: 'numbers' }
},
bullets: {
on: { NONE: 'none', NUMBERS: 'numbers' }
},
numbers: {
on: { BULLETS: 'bullets', NONE: 'none' }
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment