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

https://github.com/johanholmerin/esaction

Tiny event delegation library
https://github.com/johanholmerin/esaction

Last synced: 2 months ago
JSON representation

Tiny event delegation library

Awesome Lists containing this project

README

        

# esaction

Tiny event delegation library, inspired by Google's
[jsaction](https://github.com/google/jsaction/). Useful as an alternative to
hydration, by serializing event listeners to DOM attributes and lazy loading the
event handler. Replays events dispatched before handler is added.

## Example

```html


// Can be inlined with Rollup or Webpack. See examples folder
import { addListeners, removeListeners } from 'esaction/contract.js';

addListeners(document.body, ['click', { name: 'touchstart', passive: true }]);
// removeListeners(document.body, ['click', { name: 'touchstart', passive: true }]);

Click me


// Can be lazily loaded
import { addHandlers, removeHandlers } from 'esaction/dispatcher.js';

// Will replay old events and listen for new
addHandlers({
buttonClickHandler(event) {
console.log(event);
}
});
// removeHandlers('buttonClickHandler', 'otherHandler');