1.0.4 • Published 5 years ago

@studiometa/events v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Events

NPM Version Dependency Status devDependency Status

Three small functions to ease events binding in Javascript.

Installation

Install the package with your favorite package manager:

yarn add @studiometa/events
# or 
npm install @studiometa/events

Usage

Import the package in your project and use the on, once and off functions to bind/unbind your events.

import { on, off } from '@studiometa/events';

const links = document.querySelectorAll('a');
const preventDefault = e => e.preventDefault();

on(links, 'click', preventDefault);
off(links, 'click', preventDefault);

Documentation

on(target, type, handler, options)

Bind the given handler to the type event on the target.

ArgumentTypeDescription
targetHTMLElement, NodeList, StringThe target of the event, can be a selector, an element or a list of elements
typeStringThe type of event
handlerFunctionThe handler function
optionsObjectOptions for the addEventListener (documentation)

once(target, type, handler, options)

Bind the given handler to one and only one type event on the target.

ArgumentTypeDescription
targetHTMLElement, NodeList, StringThe target of the event, can be a selector, an element or a list of elements
typeStringThe type of event
handlerFunctionThe handler function
optionsObjectOptions for the addEventListener (documentation)

off(target, type, handler)

Unbind the given handler for the type event on the given target.

ArgumentTypeDescription
targetHTMLElement, NodeList, StringThe target of the event, can be a selector, an element or a list of elements
typeStringThe type of event
handlerFunctionThe handler function
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.0

5 years ago