Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/himynameisdave/browser-event-utils
- Owner: himynameisdave
- License: mit
- Created: 2019-03-01T23:39:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:41:10.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T00:13:53.842Z (about 1 month ago)
- Topics: browser-events, event-handling, event-target, higher-order-functions, keyboard, keypress, preventdefault, stoppropagation, utilities
- Language: TypeScript
- Homepage: https://himynameisdave.github.io/browser-event-utils
- Size: 2.62 MB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
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](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-utilsyarn 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)._