npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

events-mixin

v1.3.0

Published

Browserify compatible fork of component/events.

Downloads

38,287

Readme

events-mixin

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.

Installation

$ npm install events-mixin

Example

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();
};

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:

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 is also a shorthand syntax for binding multiple events with one call:

events.bind({
  'click .remove': 'remove',
  'click .close': 'hide'
});

Events.unbind([event], [method])

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()

License

MIT