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
- Host: GitHub
- URL: https://github.com/johanholmerin/esaction
- Owner: johanholmerin
- License: mit
- Created: 2018-10-08T16:43:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-17T18:16:16.000Z (over 6 years ago)
- Last Synced: 2025-02-02T17:39:53.696Z (4 months ago)
- Language: JavaScript
- Size: 147 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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');