Skip to content

cameronhunter/event-matchers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Matchers

Build Status NPM Version License

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

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
}));

About

Composable functions for handling event callbacks in JS

Resources

License

Stars

Watchers

Forks

Packages

No packages published