Skip to content

Instantly share code, notes, and snippets.

@steveruizok
Created November 21, 2019 18:50
Show Gist options
  • Save steveruizok/912eed00d35462491ad8b70d566c5959 to your computer and use it in GitHub Desktop.
Save steveruizok/912eed00d35462491ad8b70d566c5959 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const isNotMax = context => context.count < 10;
const isNotMin = context => context.count > 0;
const increment = context => context.count + 1;
const decrement = context => context.count - 1;
const counterMachine = Machine({
initial: 'active',
context: {
count: 0
},
states: {
inactive: {
on: {
TURN_ON: "active"
}
},
active: {
on: {
TURN_OFF: "inactive",
INCREMENT: {
actions: assign({ count: increment }),
cond: isNotMax
},
DECREMENT: {
actions: assign({ count: decrement }),
cond: isNotMin
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment