nanostate
nanostate copied to clipboard
Guard action
@goto-bus-stop Guard allows the user to define when a state should not be allowed to advanced to. The nice thing about this is that the logic between multiple machines can stay tightly coupled as part of attributes about the machine. Thus, the logic does not have to be managed by application state. Let me know if there is something I can improve or any feedback.
I've also included onchange to allow listening for arbitrary changes in state
var machine = nanostate("green", {
green: { timer: "yellow" },
yellow: { timer: "red" },
red: { timer: "green" },
});
machine.onchange((nextState) => {
// nextState == yellow
});