Skip to content

Instantly share code, notes, and snippets.

andrewgordstewart

Block or report user

Report or block andrewgordstewart

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View machine.js
function fetchData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(Math.floor(Math.random() * 100));
}, 2000)
})
}
const fetchMachine = Machine({
id: 'fetch',
View machine.js
const fileMachine = Machine({
id: 'file',
type: 'parallel',
states: {
upload: {
initial: 'idle',
states: {
idle: {
on: {
INIT_UPLOAD: 'pending',
View machine.js
const config = {
key: 'virtual-funding-as-hub',
initial: 'createChannels',
states: {
createChannels: {
entry: 'assignChannels',
type: 'parallel',
states: {
createLeftGuarantorChannel: {
invoke: { src: 'createNullChannel', data: 'guarantorChannelArgs' },
View machine.js
const minuteMachine = Machine({
id: 'timer',
initial: 'active',
states: {
active: {
after: {
5000: 'finished'
}
},
finished: { type: 'final', entry: sendParent('TIMES_UP') }
View machine.js
const config = {
key: 'ledger-update',
initial: 'vote',
states: {
vote: {
on: {
'': [
{ target: 'waiting', cond: 'turnNumberCorrect', actions: 'vote' },
{ target: 'failure', cond: 'turnNumberIncorrect' }
]
View machine.js
const config = {
key: 'respond-to-challenge',
initial: 'start',
states: {
start: {
on: {
'': [
{
target: 'submitResponse',
cond: 'haveResponse',
View machine.js
const config = {
key: 'declarative-ledger-update',
initial: 'start',
states: {
start: {
entry: 'voteForGoal',
on: {
CHANNEL_UPDATED: [
{ target: 'start', cond: 'shouldVote', actions: 'voteForGoal' },
{ target: 'success', cond: 'consensusReached' },
View machine.js
// You can click on the enabled (ie. blue) actions in the diagram, and view the current state in the "state" tab on the right.
// For simplicity, the `PROPOSE_NEW_OUTCOME`
// event uses nextOutcome() to assign the
// proposed outcome.
// You can proposedOutcome in the
// customActions object with the following
//
// proposedOutcome: function(c, event) {
// return event.outcome;
@andrewgordstewart
andrewgordstewart / SketchSystems.spec
Last active Nov 14, 2019
Different Outcome Proposed
View SketchSystems.spec
Different Outcome Proposed
Voting
vote -> Consensus Reached?
reject -> Current Outcome
Consensus Reached?
yes -> Updating Outcome
no -> Voting
Equal Outcome Proposed
Current Outcome*
View toggle-machine.ts
interface ToggleMachineState {
states: {
inactive: {};
active: {};
};
}
type ToggleEvent = { type: 'TOGGLE' };
type ToggleMachineConfig = MachineConfig<
You can’t perform that action at this time.