Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
events-mixin
Advanced tools
Browserify compatible fork of component/events.
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.
$ npm install events-mixin
var events = require('events-mixin');
var el = document.querySelector('.user');
var view = new UserView(el);
function UserView(el) {
this.events = events(el, this);
this.events.bind('click .remove', 'remove');
this.events.bind('click .hide', 'hide');
}
UserView.prototype.remove = function(){
// remove the user
this.hide();
};
UserView.prototype.hide = function(){
// hide the view
};
UserView.prototype.destroy = function(){
// clean up anything you need to
this.events.unbind();
};
Initialize a new events manager targetting the
given element. Methods are delegated to obj
.
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
:
events.bind('mousedown')
events.bind('mousemove')
events.bind('mouseup')
Alternatively you may specify the method
name:
events.bind('click', 'toggleDisplay')
To use event delegation simply pass a selector after the event name as shown here:
events.bind('click .remove', 'remove')
events.bind('click .close', 'hide')
You may bind to the same element with several events if necessary,
for example here perhaps .remove()
does not manually invoke .hide()
:
events.bind('click .remove', 'remove')
events.bind('click .remove', 'hide')
events.bind('click .close', 'hide')
Addition arguments are passed to the callee, which is helpful for slight variations of a method, for example sorting:
events.bind('click .sort-asc', 'sort', 'asc')
events.bind('click .sort-dsc', 'sort', 'dsc')
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:
events.unbind('click', 'remove')
events.unbind('click', 'hide')
events.unbind('click')
events.unbind()
MIT
FAQs
Browserify compatible fork of component/events.
The npm package events-mixin receives a total of 11,616 weekly downloads. As such, events-mixin popularity was classified as popular.
We found that events-mixin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.