Dom-Emitter
A mixin class for managing the events of a MVC style View.
Features
- stores all listeners making cleanup easy
- one DOM binding per event type
- intuitive delegation
- emits proper DOM events
- convenient method binding
- efficient context binding (no fn.bind(this))
Installation
$ {package mananger} install jkroso/dom-emitter
then in your app:
var Emitter =
API
Emitter(object)
mix Emitter
methods on to object
Emitter.on(type:String, [fn]:String)
Bind fn
to type
events. When fn
is undefined
it will be inferred from type
. Delegation can also be
specified in type
by leaving a space then a css
selector which is relative to this.el
.
this this this // implies "onClick" this // delegates to `.ok`
Emitter.off(type:String, [method]:String)
unbind fn
from type
events
All the following are equivalent:
thisthisthis
Emitter.emit(topic:String, [data]:Object)
Create a DOM event and send it down to this.el
.
Any data you pass will be merged with the event
object.
thisthisthis
bind()
hook into the DOM
unbind()
unhook from the DOM
bindEvents(self:emitter)
convenience function for binding all events