Skip to content

Instantly share code, notes, and snippets.

@axelnormand
Last active December 1, 2020 11:37
Show Gist options
  • Save axelnormand/9ef829e842eae5506cda482f6e44b03e to your computer and use it in GitHub Desktop.
Save axelnormand/9ef829e842eae5506cda482f6e44b03e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
//
// Paste into: https://xstate.js.org/viz/
// Trying out a state chart to model the idea flow
//
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const ideaMachine = Machine(
{
id: "idea",
initial: "new",
context: {
expiry: 30 * 1000, // small timer here in milliseconds for illustrative purposes
observationPeriod: 20 * 1000, // small timer here in milliseconds for illustrative purposes
isVisible: false,
isBeingEvaluated: false,
},
states: {
new: {
on: {
ACTIVATE: "active",
DRAFT: "draft",
},
},
draft: {
on: {
UPDATE_DRAFT: "draft",
ACTIVATE: "active",
DELETE: "deleted",
},
},
active: {
entry: ["startEvaluating", "makeVisible"],
after: {
EXPIRY_DELAY: "expired",
},
on: {
CLOSE: "closed",
},
},
closed: {
after: {
OBSERVATION_PERIOD_DELAY: "evaluated",
},
},
expired: {
after: {
OBSERVATION_PERIOD_DELAY: "evaluated",
},
},
evaluated: {
entry: ["stopEvaluating"],
type: "final",
},
deleted: {
type: "final",
},
},
},
{
actions: {
startEvaluating: () => {
assign({
isBeingEvaluated: true,
});
},
stopEvaluating: () => {
assign({
isBeingEvaluated: true,
});
},
makeVisible: () => {
assign({
isVisible: true,
});
},
},
delays: {
EXPIRY_DELAY: (context) => {
return context.expiry;
},
OBSERVATION_PERIOD_DELAY: (context) => {
return context.observationPeriod;
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment