Skip to content

Instantly share code, notes, and snippets.

@tkh44
Last active February 11, 2021 21:20
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 tkh44/199295c10327aa46c2412b5130caebe8 to your computer and use it in GitHub Desktop.
Save tkh44/199295c10327aa46c2412b5130caebe8 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 createAttackMachine = Machine({
id: "create-attack",
initial: "loading",
context: {
targetType: "HOST",
target: {},
impact: {},
schedule: {},
retries: 0
},
states: {
error: {
on: {
RETRY: {
target: "loading",
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
},
loading: {
on: {
SUCCESS: "attackTypeSelection",
ERROR: "error"
}
},
attackTypeSelection: {
on: {
SELECT_HOST: 'hostTarget',
SELECT_CONTAINER: 'containerTarget',
SELECT_KUBERNETES: "kubernetesTarget"
}
},
hostTarget: {
on: {
SUBMIT: {
target: "impact",
actions: assign({
target: (_, event) => event.value
})
}
}
},
containerTarget: {
on: {
SUBMIT: {
target: "impact",
actions: assign({
target: (_, event) => event.value
})
}
}
},
kubernetesTarget: {
on: {
SUBMIT: {
target: "impact",
actions: assign({
target: (_, event) => event.value
})
}
}
},
impact: {
on: {
SUBMIT: {
target: "review",
actions: assign({
impact: (_, event) => event.value
})
}
}
},
schedule: {
on: {
SUBMIT: {
target: "review",
actions: assign({
schedule: (_, event) => event.value
})
}
}
},
review: {
on: {
SUBMIT: "saving",
OPEN_TARGET: "attackTypeSelection",
OPEN_IMPACT: "impact",
OPEN_SCHEDULE: "schedule"
}
},
saving: {
on: {
SUCCESS: {
target: "attackTypeSelection"
},
ERROR: {
target: "review"
}
}
}
}
},
{
guards: {
isHostTarget: (context) => {
return context.targetType === "HOST";
},
isContainerTarget: (context) => {
return context.targetType === "CONTAINER";
},
isKubernetesTarget: (context) => {
return context.targetType === "KUBERNETES";
},
verifyHostTarget: (context) => {
return context.targetType === "HOST";
},
verifyContainerTarget: (context) => {
return context.targetType === "CONTAINER";
},
verifyKubernetesTarget: (context) => {
return context.targetType === "KUBERNETES";
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment