Created
October 8, 2020 16:21
-
-
Save axelnormand/a7ea2ad209e07ce4d45d489bfad0e991 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const ideaMachine = Machine( | |
{ | |
id: "idea", | |
initial: "draft", | |
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, | |
ideaVisibility: "private", // private or public // TODO: make this work | |
isIdeaInUserScore: false, // TODO: make this work | |
}, | |
states: { | |
draft: { | |
on: { | |
SUBMIT: "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