Statelet
Sometimes we have a pattern like:
if is_ready // do the thingelse // put into a queue and execute when is_ready=true
Events make it better:
emitter;
But what if you start listening too late and you miss the event? You'll be waiting forever...
statelet
takes a different approach where instead of listening for events we're watching for changes in state:
is_ready;
Combining States
Sometimes you want to know when multiple states align in a certain way.
var State = ; var is_happy = ;var knows_it = ;var action = ; { var youre_happy = is_happy; var you_know_it = knows_it; if youre_happy && you_know_it action; }is_happy;knows_it;
Where can I use it?
Works in both node.js and browser.
Install
npm install statelet
To do
- make sure examples have decent cross-browser support
- more examples
License
MIT