emoter
v0.1.0
Published
the event emitter for states
Downloads
4
Maintainers
Readme
emoter
JavaScript event emitter for state changes
emoter uses energy and skate to emit events for state changes
npm install emoter --save
Create an emoter instance
var emoter = require('emoter')
var app = emoter()
Methods
.state
app.state(state)
// getapp.state(state, value)
// set (triggers listeners if change)
.on
app.on(state, listener)
listen to state changes
.off
app.off(state, listener)
remove listenerapp.off(state)
remove all state listenersapp.off()
remove all listeners
.once
app.on(state, listener)
listen for the next state change
.emit
app.emit(state)
manually trigger state listeners
Example
var emoter = require('emoter')
var app = emoter()
app.on('user', function() {
console.log(this.state('user'))
})
app.state('user', 47) // logs 47
app.state('user', 81) // logs 81
app.on('loading', function() {
if (this.state('loading')) console.log('loading')
}).on('loaded', function() {
if (this.state('loaded')) console.log('loaded')
})
app.load = function() {
this.state('loading', true)
// ...
this.state('loading', false)
this.state('loaded', true)
}
app.load()
Compatibility
Works in web browsers and node
License
MIT