https://github.com/cameronhunter/event-matchers
Composable functions for handling event callbacks in JS
https://github.com/cameronhunter/event-matchers
Last synced: 4 months ago
JSON representation
Composable functions for handling event callbacks in JS
- Host: GitHub
- URL: https://github.com/cameronhunter/event-matchers
- Owner: cameronhunter
- License: mit
- Created: 2016-02-28T23:45:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T17:43:26.000Z (about 9 years ago)
- Last Synced: 2025-10-30T05:21:34.092Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Event Matchers
[](https://travis-ci.org/cameronhunter/event-matchers) [](https://npmjs.org/package/event-matchers) [](https://github.com/cameronhunter/event-matchers/blob/master/LICENSE.md)
Composable functions for handling event callbacks in Vanilla JS. Build complex
event handlers by composing simple event matchers. Separate event handling logic
from the behavior logic that the event triggers.
## Example
```javascript
import { all, any, delegate, keycode } from 'event-matchers';
const up = keycode('ArrowUp');
const down = keycode('ArrowDown');
const left = keycode('ArrowLeft');
const right = keycode('ArrowRight');
const matcher = all(
any(up, down, left, right),
delegate('.controls')
);
document.addEventListener('keydown', matcher(function(e) {
// Only triggered when arrow keys occur on the .controls element
}));
```