0.1.4 • Published 8 years ago

event-registrar v0.1.4

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

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

EventRegistrar

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

ParamTypeDescription
targetEventTargetthe target to which the listener will be attached
eventStringthe name of the event to which the listener will be bound
callbackfunctionthe 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();
0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago