$ npm install bloody-events
var events = require("bloody-events")
Creates an event object
Creates an event-object subclass
Listens to the type
event with listener
as callback.
once
defines whether or not the listener should remove itself afterwards.
A listener can either be a function or an object containing a handleEvent
interface.
events.on("user:log", function(username){
model.set({
username : username
})
})
// or
var model = model
.extend({
getDefaults : function(){
return {
username : ""
}
},
handleEvent : function(username){
this.set({
username : username
})
}
})
.create()
events.on("user:log", model)
// or
var model = model
.extend({
getDefaults : function(){
return {
username : "",
isThere : true
}
},
handleEvent : {
"user:log" : function(username){
this.set({
username : username
})
},
"user:leave" : function(){
this.set({
isThere : false
})
}
}
})
.create()
events.on("user:log", model)
chainable, returns this
Shortcut for .listen(type, listener, true)
chainable, returns this
If type
and listener
are passed, removes the given listener
.
If only type
is passed, removes all this type's listeners.
Otherwise, removes all the events listeners.
chainable, returns this
Triggers synchronously the type
events, and passes args…
as arguments for the listeners.
returns true
if any callback has been executed
returns false
otherwise
- call
events.constructor.call(this)
in your constructor - call
events.destructor.call(this)
in your destructor