@taufik-nurrohman/event
v1.0.1
Published
Utility of native event listener implementation.
Downloads
724
Maintainers
Readme
Event Utility
Utility of native event listener implementation.
Usage
CommonJS
const {onEvent} = require('@taufik-nurrohman/event');
onEvent('resize', window, e => {
console.log([
window.innerHeight,
window.innerWidth
]);
});
ECMAScript
import {onEvent} from '@taufik-nurrohman/event';
onEvent('resize', window, e => {
console.log([
window.innerHeight,
window.innerWidth
]);
});
Methods
event(name, options = {}, cache = false)
Create custom events with unique name.
let readyEvent = event('ready');
events
List of custom events cache created by event
.
console.log(events);
fireEvent(event, node, options = {}, cache = false)
onEvent('DOMContentLoaded', document, event => {
fireEvent('ready', document);
});
fireEvents(events, node, options = {}, cache = false)
offEvent(event, node, then)
offEvent('ready', document, onDocumentReady);
offEventDefault(event)
offEventImmediatePropagation(event)
offEventPropagation(event)
offEvents(events, node, then)
onEvent(event, node, then, options = false)
function onDocumentReady() {
console.log('Document is ready!');
}
onEvent('ready', document, onDocumentReady);