Skip to content

Instantly share code, notes, and snippets.

@gyula-ny
Last active January 28, 2020 13:41
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 gyula-ny/b408b7ca93856bf5bdd978e3a365806f to your computer and use it in GitHub Desktop.
Save gyula-ny/b408b7ca93856bf5bdd978e3a365806f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const { log } = actions;
const fetchMachine = Machine(
{
id: 'helloWorld',
initial: 'pending',
context: {
rejections: []
},
states: {
pending: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
states: {
CatalogListing: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
CatalogListing_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
CatalogListing_APPROVED: 'done',
CatalogListing_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
BusinessCase: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
BusinessCase_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
BusinessCase_APPROVED: 'done',
BusinessCase_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
Security: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
Security_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
Security_APPROVED: 'done',
Security_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
Monitoring: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
Monitoring_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
Monitoring_APPROVED: 'done',
Monitoring_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
}
},
onDone: 'waitingPushToOnDeck',
type: 'parallel'
},
waitingPushToOnDeck: {
on: {
PUSHTOONDECK: {
target: 'OnDeck',
actions: ['announceStageChange']
}
},
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`)
},
OnDeck: {
entry: ['stageEntryNotification', 'logEntry'],
states: {
CatalogListing: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
CatalogListing_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
CatalogListing_APPROVED: 'done',
CatalogListing_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
BusinessCase: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
BusinessCase_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
BusinessCase_APPROVED: 'done',
BusinessCase_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
Security: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
Security_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
Security_APPROVED: 'done',
Security_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
},
Monitoring: {
initial: 'pending',
type: 'compound',
states: {
pending: {
on: {
Monitoring_SUBMIT: 'submitted'
}
},
submitted: {
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`),
on: {
Monitoring_APPROVED: 'done',
Monitoring_REJECTED: {
target: 'pending',
actions: assign((context, event) => {
return {
rejections: context.rejections.concat({
when: Number(new Date()),
reason: event.reason
})
};
})
}
}
},
done: {
type: 'final'
}
}
}
},
onDone: 'waitingPushToProd',
type: 'parallel'
},
waitingPushToProd: {
on: {
PUSHTOPROD: 'PROD'
},
entry: log((context, event) => `STATE ENTRY: ${JSON.stringify(event)}`),
exit: log((context, event) => `STATE EXIT: ${JSON.stringify(event)}`)
},
PROD: {
type: 'final'
}
}
}
, {
actions: {
announceStageChange: (conext, event, actionMeta) => {
const { action, state } = actionMeta;
const { value } = state;
alert("KAFKA NOTIFY: the Service is successfully advanced to new stage: " + JSON.stringify(value));
},
stageEntryNotification: (context, event) => { console.log("we entered new state")},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment