Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created December 22, 2019 21:04
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kyleshevlin/4b6f4913fea03976f32cf96545f5041b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const filterSubStates = filterName => ({
initial: "disabled",
states: {
disabled: {
on: { [`ENABLE_${filterName}`]: "enabled" }
},
enabled: {
initial: "asc",
on: {
[`DISABLE_${filterName}`]: "disabled"
},
states: {
asc: {
on: { [`TOGGLE_SORT_ORDER_FOR_${filterName}`]: "desc" }
},
desc: {
on: { [`TOGGLE_SORT_ORDER_FOR_${filterName}`]: "asc" }
}
}
}
}
});
const filterMachine = Machine({
id: "filter",
type: "parallel",
on: {
RESET: {
target: ["byEmail.disabled", "byId.disabled", "byName.disabled"]
}
},
states: {
byEmail: {
...filterSubStates("EMAIL")
},
byId: {
...filterSubStates("ID")
},
byName: {
...filterSubStates("NAME")
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment