lit-dispatcher
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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

Method Parameters Description
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

Readme

Keywords

none

Package Sidebar

Install

npm i lit-dispatcher

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

16 kB

Total Files

15

Last publish

Collaborators

  • pavelmazhuga