raix:eventstate 
Adds a simple api for maintaining evented state.
This object inherit from the EventEmitter
and adds two functions to the api:
emitState
clearState
The EventState
constructor takes an object / map of initial / default state values if any.
Examples:
1 var es = new EventState({ 2 // Define an initial state with default value 3 'initial': { data: 'foo' } 4 }); 5 6 // Emit a ready state with data of `null` 7 es.emitState('ready'); 8 9 // Emit an "initial" state with data 10 es.emitState('initial', { data: 'foo' });
Listening to states:
1 es.once('ready', function() { 2 // Run once ready / already ready 3 }); 4 5 es.addListener('initial', function(value) { 6 // Get the value and have it kept updated on changes 7 });
Cleanup listeners and state value for ready
state:
1 // Removes all listeners for event `ready` 2 es.removeAllListeners('ready'); 3 4 // Empty value map 5 es.clearState('ready');
Cleanup all listeners and state values:
1 // Removes all listeners 2 es.removeAllListeners(); 3 4 // Empty value map 5 es.clearState();
Kind regards Morten