This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@studiometa/events

1.0.4 • Public • Published

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.

Argument Type Description
target HTMLElement, NodeList, String The target of the event, can be a selector, an element or a list of elements
type String The type of event
handler Function The handler function
options Object Options for the addEventListener (documentation)

once(target, type, handler, options)

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

Argument Type Description
target HTMLElement, NodeList, String The target of the event, can be a selector, an element or a list of elements
type String The type of event
handler Function The handler function
options Object Options for the addEventListener (documentation)

off(target, type, handler)

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

Argument Type Description
target HTMLElement, NodeList, String The target of the event, can be a selector, an element or a list of elements
type String The type of event
handler Function The handler function

Package Sidebar

Install

npm i @studiometa/events

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

18.9 kB

Total Files

11

Last publish

Collaborators

  • jeremiewerner