Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/himynameisdave/browser-event-utils

🎟 A collection of higher-order functions for invoking common browser event methods.
https://github.com/himynameisdave/browser-event-utils

browser-events event-handling event-target higher-order-functions keyboard keypress preventdefault stoppropagation utilities

Last synced: 5 days ago
JSON representation

🎟 A collection of higher-order functions for invoking common browser event methods.

Awesome Lists containing this project

README

        


browser-event-utils


🎟 A collection of higher-order functions for invoking common browser event methods.




Travis Badge


Coverage Status


Bundle size (minified)


Downloads





---

### 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](https://bundlephobia.com/result?p=browser-event-utils)) package aims to provide you with a set of [higher-order functions](https://eloquentjavascript.net/05_higher_order.html) 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)**](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well) 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](https://reactjs.org/docs/events.html#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:

```html

```

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

### Documentation

Please view the [documentation](https://himynameisdave.github.io/browser-event-utils) for guides to explore what methods this package exposes and how to use them.

### Contributing

Please read the [contributing guidelines](https://github.com/himynameisdave/browser-event-utils/blob/master/.github/CONTRIBUTING.md) for more info.

### Migration

For information on migrating between major versions of this package, please review the [migration guide](https://github.com/himynameisdave/browser-event-utils/blob/master/.github/MIGRATION_GUIDE.md).

---

_✌️ Built by [Dave Lunny](http://himynameisdave.com)._