Skip to content

ChrisBauer/event-registrar

Repository files navigation

event-registrar

Provides an easy way to provide callbacks for when the browser crosses the threshold of a media query. Uses the Observable API to allow for composable event streams

getting the code

install from npm: npm install event-registrar

use in your project:

import {EventRegistrar} from 'event-registar';
const registrar = new EventRegistrar();

Or

var EventRegistrar = require('event-registrar');
var registrar = new EventRegistrar();

running the tests

Install the dependencies using npm install

Run the tests using npm test

Transpile to ES5 using npm run build

Build the docs using npm run doc

Generate the docs for the readme with npm run build-readme

API Reference

Kind: global class

new EventRegistrar()

provides a simple and consistent way to attach DOM event listeners, particularly when the goal is to attach multiple to a single event handler, such as window.onscroll

eventRegistrar.register(target, event, callback) ⇒

Provides a way to register a callback to be fired when the specified event is triggered. Generally should be used as a Singleton through a dependency injection container.

For more information about the EventTarget type, check out the MDN docs.

Kind: instance method of EventRegistrar
Returns: Function an unsubscribe function

Param Type Description
target EventTarget the target to which the listener will be attached
event String the name of the event to which the listener will be bound
callback function the callback function to be executed when the event occurs

Example

const registrar = new EventRegistrar();
// register
const unreg = registrar.register(window, 'onscroll', (ev) => console.log(ev) );
.
.
.
// cleanup
unreg();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published