Add event utils

This commit is contained in:
atomiks
2018-01-05 23:33:48 +11:00
parent 6e610f15e7
commit 4f727a59bc
3 changed files with 43 additions and 0 deletions

16
snippets/off.md Normal file
View File

@ -0,0 +1,16 @@
### off
Removes an event listener from an element.
Use `EventTarget.removeEventListener()` to remove an event listener to an element.
```js
const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts);
```
```js
// See the `on` snippet.
const fn = () => console.log('!');
const ref = on(document.body, 'click', fn, { target: 'p' });
off(document.body, 'click', ref); // no longer logs '!' upon clicking a `p` el child of the body
```