Skip to content

Instantly share code, notes, and snippets.

@Santiago-j-s
Created September 13, 2021 02:37
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 Santiago-j-s/6a9919a356c9bc1e46693ce09b2c5867 to your computer and use it in GitHub Desktop.
Save Santiago-j-s/6a9919a356c9bc1e46693ce09b2c5867 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const DIAS_CRITICIDAD_MEDIA = 20;
const DIAS_CRITICIDAD_ALTA = 10;
const DIAS_VENCIDO = 0;
const isProximoAVencer = (context) =>
context?.days <= DIAS_CRITICIDAD_ALTA;
const isVencido = (context) => context?.days <= 0;
const isCriticidadMedia = (context) =>
context?.days <= DIAS_CRITICIDAD_MEDIA;
const assignDias = (_ctx, ev) => ev.dias;
context = { dias: undefined }
Machine({
initial: "idle",
context,
actions: { assignDias: assignDias },
states: {
idle: {
on: {
NUEVO_CHECKLIST: "checklist",
NUEVO_VENCIMIENTO: {
target: "vencimiento",
actions: [assignDias],
},
},
},
checklist: {
initial: "initial",
context,
states: {
initial: {
on: {
APROBAR: "aprobado",
RECHAZAR: "rechazado",
},
},
aprobado: {
on: {
REPARAR: "enReparacion",
},
},
enReparacion: {
on: {
PENDIENTE: "pendiente",
REALIZADO: "realizado",
},
},
pendiente: {
on: {
REALIZADO: "realizado",
},
},
realizado: {
type: "final",
},
rechazado: {
type: "final",
},
},
},
vencimiento: {
initial: "idle",
context,
states: {
idle: {
always: [
{
target: "pendiente",
},
{
target: "isProximoAVencer",
cond: isProximoAVencer,
},
{
target: "vencido",
cond: isVencido,
},
],
},
pendiente: {
on: {
REALIZAR: "realizado",
},
initial: "idle",
context,
states: {
idle: {
always: [
{
target: "criticidadMedia",
cond: isCriticidadMedia,
},
{
target: "criticidadLeve",
},
],
},
criticidadLeve: {
type: "final",
},
criticidadMedia: {
type: "final",
},
},
},
isProximoAVencer: {
on: {
REALIZAR: "realizado",
},
context,
states: {
criticidadAlta: {
type: "final",
},
},
},
vencido: {
on: {
REALIZAR: "realizado",
},
context,
states: {
criticidadAlta: {
type: "final",
},
},
},
realizado: {
type: "final",
},
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment