Skip to content

๐ŸŽŸ A collection of higher-order functions for invoking common browser event methods.

License

Notifications You must be signed in to change notification settings

himynameisdave/browser-event-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

browser-event-utils

๐ŸŽŸ A collection of higher-order functions for invoking common browser event methods.


Motivation

How often do you call stuff like event.preventDefault or event.stopPropagation when handling events in client-side JavaScript? I bet it's pretty often.

This (~1kb) package aims to provide you with a set of higher-order functions which handle these things for you.

Could you survive without this library? Absolutely. But I've found that in larger codebases, it can become cumbersome to always sprinkle e.preventDefault() calls all over the place. It adds complexity to your event handlers, which violates the Do One Thing (DOT) principal, plus it (in theory) could make your unit tests more complicated (if you care about asserting that event methods are called).

This library can also help aleviate some of the pains surrounding event pooling in React.

Installation

This package is available on NPM, and you can install it with npm or yarn:

npm install browser-event-utils

yarn add browser-event-utils

Browser/UMD

If you want to just import this library directly in the browser, you can add the following script tag:

<script src="https://unpkg.com/browser-event-utils/bin/index.umd.js" />

This will expose a browserEventUtils global, on which you will find all of the utility methods.

Documentation

Please view the documentation for guides to explore what methods this package exposes and how to use them.

Contributing

Please read the contributing guidelines for more info.

Migration

For information on migrating between major versions of this package, please review the migration guide.


โœŒ๏ธ Built by Dave Lunny.