All Projects → zzarcon → Default Passive Events

zzarcon / Default Passive Events

Licence: mit
Makes {passive: true} by default when EventListenerOptions are supported

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Default Passive Events

Swissarmylib
Collection of helpful utilities we use in our Unity projects.
Stars: ✭ 154 (-45.96%)
Mutual labels:  events, performance
Domtastic
Small, fast, and modular DOM and event library for modern browsers.
Stars: ✭ 763 (+167.72%)
Mutual labels:  events, performance
Laravel Transactional Events
Transaction-aware Event Dispatcher for Laravel
Stars: ✭ 263 (-7.72%)
Mutual labels:  events
Shiba
Catch bad SQL queries before they cause problems in production
Stars: ✭ 277 (-2.81%)
Mutual labels:  performance
Webpack Lighthouse Plugin
A Webpack plugin for Lighthouse
Stars: ✭ 271 (-4.91%)
Mutual labels:  performance
Event Sourcing Cqrs Examples
Event Sourcing and CQRS in practice.
Stars: ✭ 265 (-7.02%)
Mutual labels:  events
Next Super Performance
The case of partial hydration (with Next and Preact)
Stars: ✭ 272 (-4.56%)
Mutual labels:  performance
Fixed
high performance fixed decimal place math library for Go
Stars: ✭ 263 (-7.72%)
Mutual labels:  performance
Wallace Cli
Pretty CSS analytics on the CLI
Stars: ✭ 281 (-1.4%)
Mutual labels:  performance
Panko serializer
High Performance JSON Serialization for ActiveRecord & Ruby Objects
Stars: ✭ 266 (-6.67%)
Mutual labels:  performance
Rustc Perf
Website for graphing performance of rustc
Stars: ✭ 272 (-4.56%)
Mutual labels:  performance
Stormpot
A fast object pool for the JVM
Stars: ✭ 267 (-6.32%)
Mutual labels:  performance
Hyperhtml
A Fast & Light Virtual DOM Alternative
Stars: ✭ 2,872 (+907.72%)
Mutual labels:  performance
String Theory
Identify and reduce memory used by duplicate .NET strings
Stars: ✭ 273 (-4.21%)
Mutual labels:  performance
React Performance
Helpers to debug and record component render performance 🚀
Stars: ✭ 265 (-7.02%)
Mutual labels:  performance
Performance Testing Framework
Framework allows to perform load testing with Apache Jmeter, view application/server metrics in real-time with Grafana, analyze errors cause with detailed traces for failed requests, compare different test runs in scripted dashboard and perform frontend performance testing with sitespeed.io+webpagetest
Stars: ✭ 275 (-3.51%)
Mutual labels:  performance
Grav
Performance visualisation tools
Stars: ✭ 262 (-8.07%)
Mutual labels:  performance
Ristretto
A high performance memory-bound Go cache
Stars: ✭ 3,584 (+1157.54%)
Mutual labels:  performance
Fastexcel
Generate and read big Excel files quickly
Stars: ✭ 268 (-5.96%)
Mutual labels:  performance
Devito
Code generation framework for automated finite difference computation
Stars: ✭ 285 (+0%)
Mutual labels:  performance

default-passive-events Build Status Dependency Status Bundle size

Makes {passive: true} by default when EventListenerOptions are supported

50 lines snippet that enables see list below). It basically will set { passive: true } automatically every time you declare a new event listener.

Installation

yarn add default-passive-events

Usage

Simply require the package:

require('default-passive-events');

or include it locally:

<script type="text/javascript" src="node_modules/default-passive-events/dist/index.js"></script>

or from unpkg CDN:

<script type="text/javascript" src="https://unpkg.com/default-passive-events"></script>

Bundle formats

This package is distributed as multiple, different types of output bundles. The most often your bundler will properly choose the correct version by itself.

To get more information about supported bundle formats have a look at official microbundle documentation. Especially interesting is the modern format which - if used properly with your bundle system - might produce significantly smaller output code.

Examples

Those are some examples and their output:

document.addEventListener('mouseup', onMouseUp); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, true); // {passive: true, capture: true}
document.addEventListener('mouseup', onMouseUp, false); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false}); // {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false, capture: false}); // {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false, capture: true}); // {passive: false, capture: true}
document.addEventListener('mouseup', onMouseUp, {passive: true, capture: false}); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: true, capture: true}); // {passive: true, capture: true}

Demo

Check the demo page for a working example.

Motivation

Just to take benefit in your apps without having to edit every single event listener you already have.

Targeted events

Default-passive-events package makes following event listeners passive by default:

  • scroll
  • wheel
  • touchstart
  • touchmove
  • touchenter
  • touchend
  • touchleave
  • mouseout
  • mouseleave
  • mouseup
  • mousedown
  • mousemove
  • mouseenter
  • mousewheel
  • mouseover

Q&A

Browser rises weird error when I try to preventDefault event inside of a passive listener.

Well, that's true, partly. First of all specification says that you shouldn't ever try to preventDefault from the context of passive listener. But if that's not a possibility you should know that in the console you see only error-looking log messages, which are not actual errors (ergo: they do not break your code).

Is there a possibility to hide these messages?

Unfortunately, no. Since they are not actual errors there is no way to catch them and (more importantly) there is no way to distinguish whether you're inside of the passive listener context to know when not to call/override preventDefault method. Now, we look at the regarding issue in WHATWG repo whatwg/dom#587.

Is there a possibility to bring default addEventListener method back for chosen elements/globally (e.g. for time of running some of the code)?

Yes, original addEventListener is available under _original property of our's addEventListener's implementation (so - element.addEventListener._original). Having that in mind, you can bring it back for however you want, e.g.:

element.addEventListener = element.addEventListener._original;

Resources

Author

@zzarcon

Maintainers

@zzarcon @frsgit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].