step-foolish
Simple step-wise state machine management.
Installation
yarn add step-foolish
...or:
npm install step-foolish
TypeScript
Types are already provided.
Example usage
; // Some example state to represent a real-world application/component state.; ; console.logmachine.currentStep; //=> `null` (does not start out on any step by // default) machine.goTo'termsOfService';// (`showTos()` happens here)console.logmachine.currentStep; //=> "termsOfService" machine.goTo'date'; // can't go to "date" yet because // `state.tosAccepted` is `false`console.logmachine.currentStep; //=> "termsOfService" state.tosAccepted = true; // now it can go to "date" machine.goTo'date';// (`hideTos()` happens here)// (`initDateSelect()` happens here)console.logmachine.currentStep; //=> "date" machine.goTo'termsOfService'; // we'll go back to "termsOfService"// (`popModal("Remember to come back and select a date!")` and// `tearDownDateSelect()` both happen here)// (`showTos()` happens here)console.logmachine.currentStep; //=> "termsOfService" state.dateSelected = true; // now that `state.tosAccepted` and // `state.dateSelected` are both true, it // could go to "time" if it wanted, but since // `state.timeSelected` is still false, it // can't yet go to "finished" machine.goTo'finished'; // let's try going to "finished" anyway...// (`hideTos()` happens here)// (`initTimeSelect()` happens here)console.logmachine.currentStep; //=> "time" (that's the farthest-along not- // yet-completed dependency for "finished") state.timeSelected = true; // now it can go to "finished" machine.goTo'finished';// (`tearDownTimeSelect()` happens here)// (`popModal("You're finished!")` happens here)console.logmachine.currentStep; //=> "finished"
Contributing
Bug reports and pull requests for this project are welcome at its GitHub page. If you choose to contribute, please be nice so I don't have to run out of bubblegum, etc.
License
This project is open source, under the terms of the MIT License.