๐ A collection of higher-order functions for invoking common browser event methods.
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.
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.
Please view the documentation for guides to explore what methods this package exposes and how to use them.
Please read the contributing guidelines for more info.
For information on migrating between major versions of this package, please review the migration guide.
โ๏ธ Built by Dave Lunny.