Skip to content

Instantly share code, notes, and snippets.

@ilya-korotya
Last active July 3, 2018 21:08
Show Gist options
  • Save ilya-korotya/98f30abf0080c978711f008da5a7e2c6 to your computer and use it in GitHub Desktop.
Save ilya-korotya/98f30abf0080c978711f008da5a7e2c6 to your computer and use it in GitHub Desktop.
Vue + xstate
new Vue({
el: "#app",
mounted() {
this.state = this.lightMachine.initial;
setInterval(() => {
this.state = this.lightMachine.transition(this.state, "TIMER").value;
}, 3000);
},
computed: {
buttonText() {
return this.buttonOptions[this.state];
}
},
data() {
return {
state: null,
lightMachine: xstate.Machine({
key: "light",
initial: "green",
states: {
green: {
on: {
TIMER: "yellow"
}
},
yellow: {
on: {
TIMER: "red"
}
},
red: {
on: {
TIMER: "green"
}
}
}
}),
buttonOptions: {
green: "foo",
yellow: "bar",
red: "baz"
}
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment