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

eslint-plugin-delegated-events

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-delegated-events

Disallow delegating high-frequency events.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-plugin-delegated-events

Disallow delegating high-frequency events.

The delegated-events library registers all event listeners on document, using selectors to determine an observer's interest in each event.

on('click', '.js-button', function(event) {
  console.log('clicked', this)
})

This is appropriate for most events, like click and change, but events fired at a high rate need to be directly bound with element.addEventListener to avoid performance problems.

This lint rule disallows delegated event listeners on the following events:

  • input
  • keydown
  • keypress
  • keyup
  • mouseout
  • mouseover
  • mousemove
  • scroll

Top level listener registration

Registering a delegated event listener by calling on in a conditional branch, loop, or function can result in duplicate registrations and invoking the listener multiple times. The global-on lint rule requires on to be called only in the top level module scope.

Installation

You'll first need to install ESLint:

$ npm install eslint --save-dev

Next, install eslint-plugin-delegated-events:

$ npm install eslint-plugin-delegated-events --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-delegated-events globally.

Usage

Add delegated-events to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": [
    "delegated-events"
  ],
  "rules": {
    "delegated-events/global-on": 2,
    "delegated-events/no-high-freq": 2
  }
}

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

Keywords

FAQs

Package last updated on 05 Sep 2019

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