eventt.js
v1.1.0
Published
Tiny event listeners manager.
Downloads
85
Maintainers
Readme
Eventt.js
🛎️ Tiny 2.1Kb event listeners manager.
Installation
Using NPM
npm i eventt.js --save
Unpkg CDN
<script src="https://unpkg.com/[email protected]/dist/eventt.js"></script>
Usage
import Eventt from 'eventt.js'
// create events instance/group
const eventt = Eventt()
// addEventListener
eventt.listen("click", "#id", () => { /* callback */ })
eventt.listen("resize", window, () => { /* callback */ })
eventt.listen(["click", "resize"], ["#id", ".selector"], () => { /* callback */ }, { /* opts */ })
eventt.listen("resize", window, () => { /* callback */ }, { uid: 'group-id' })
// getEventListeners
eventt.list(".selector", (events) => { /* first argument = events array */ })
// dispatchEvent
eventt.trigger("click", "*")
eventt.trigger("*", ["#id", ".selector"])
eventt.trigger("resize", window, 'group-id')
// removeEventListener
eventt.unlisten("click", "*")
eventt.unlisten("*", ".selector")
eventt.unlisten("*", window, 'group-id')
Options
It is possible to pass different options to the Event({ /* options here */ })
instance:
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| intercept
| boolean | false
| If set to true
, all the native .addEventListener()
and .removeEventListener()
calls will be intercepted and transformed into .listen()
and .unlisten()
. This can be particularly useful in case you want to implement Eventt.js into an already existing project, without having to update your existing code. |
| debug
| boolean | false
| If set to true
, every action performed will output debugging information into the console
. |
Browser Support
Fully supported by Evergreen Browsers (Edge, Opera, Safari, Firefox & Chrome) and IE 10+ browsers.
For older browsers support like IE9, you may need to include the following Polyfill library on your site:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
Contribution
npm run watch
npm run test
License
MIT © 2017 Sylvain Simao