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
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();
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
Kind: global class
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
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();