2.1.0 • Published 4 years ago

lit-dispatcher v2.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

LitDispatcher

A lightweight (< 1kb gzipped) dispatcher. Written in TypeScript.

Installation

Install it from NPM: npm i lit-dispatcher

IMPORTANT: The library's default compilation target is ES6. If you need to support ES5 environments - consider transpiling it.

Usage

import createLitDispatcher from 'lit-dispatcher';

const dispatcher = createLitDispatcher();

// Usage Example
dispatcher.on('my-event', ({ customData }) => {
    // ...
});

// Somewhere in the code
dispatcher.dispatch('my-event', { customData: 'value' });

API

Methods

MethodParametersDescription
on(eventName: string, callback: (data: any) => void)Subscribe to an event
off(eventName?: string, callback?: (data: any) => void)Unsubscribe method. If both eventName and callback are provided, unregister a specified callback only. If only eventName is provided, unregister all callbacks for this particular event. If no arguments provided - unregister all callbacks (basically, destroy the dispatcher).
dispatch(eventName: string, data?: any)Dispatch an event with optional data
2.1.0

4 years ago

2.0.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago