You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Higher level dom event management with direct and delegate event handling support.
This component makes subscription management easy and unobtrusive since it does not muck with your view prototypes. Unbinding to "clean up" after your view is as simple as invoking this.events.unbind(), or more specific unbinds may be performed.
It's design to work with a "host" object, typically a view, that provides callbacks, making callback management much less tedious than libraries like jQuery.
Installation
$ component install component/events
Example
varevents=require('events');varel=document.querySelector('.user');varview=newUserView(el);functionUserView(el){this.events=events(el,this);this.events.bind('click .remove','remove');this.events.bind('click .hide','hide');}UserView.prototype.remove=function(){// remove the userthis.hide();};UserView.prototype.hide=function(){// hide the view};UserView.prototype.destroy=function(){// clean up anything you need tothis.events.unbind();};
API
Events(el, obj)
Initialize a new events manager targetting the
given element. Methods are delegated to obj.
Events#bind(event, [method])
Bind direct event handlers or delegates with event and
invoke method when the event occurs, passing the event object.
When method is not defined the event name prefixed with "on" is used.
For example the following will invoke onmousedown, onmousemove,
and onmouseup:
There are three flavours of unbinding -- you may unbind all
event handlers, all specific to event, or all specific to
event and the given method. For example these are all valid: