Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-view-events

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-view-events

Simple helper for adding events to an element, backbone object style

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

add-view-events

Adds delegated event listeners to an element, optionally binding the callbacks to a context, allows for easy removal of event listeners on cleanup

npm install add-view-events

Usage

var addEvents = require('./add-view-events')

function SomeView() {
  this.el = document.createElement('div')
  this.removeEvents = addEvents(this.el, {
      'click button.some-class': this.shout
  }, this)
}

SomeView.prototype.shout = function() {
  alert(this.msg)
}

SomeView.prototype.remove = function() {
  this.removeEvents()
  this.el.remove()
}

API

addEvents(el, events[, context])

Attach event listeners and returns a cleanup function. el should be an element, events should be an object with 'event elem.selector' keys and function properties.

The context argument is optional and will ensure callbacks are called with their context bound to context

Keywords

FAQs

Package last updated on 12 Oct 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc