Skip to content

Instantly share code, notes, and snippets.

@souporserious
Last active October 28, 2019 05:55
Show Gist options
  • Save souporserious/2acd1322128e789e2a19e9c3924cf33d to your computer and use it in GitHub Desktop.
Save souporserious/2acd1322128e789e2a19e9c3924cf33d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const highlightAction = amount =>
assign({
highlightedIndex: (context, event) =>
context.highlightedIndex === null ? 0 : context.highlightedIndex + amount
});
const highlightMachine = Machine({
id: "highlight",
initial: "idle",
context: {
highlightedIndex: null
},
states: {
idle: {
on: {
ARROW_UP: {
target: "idle",
actions: highlightAction(-1)
},
ARROW_DOWN: {
target: "idle",
actions: highlightAction(1)
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment