@mertsolak/custom-event
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Custom Event

Developed to use CustomEvents easily.

npm license size issue

Installation

Use node package manager to install @mertsolak/custom-event.

npm i @mertsolak/custom-event

Usage

import { on, off, once, trigger, broadcast, respond, request } from '@mertsolak/custom-event';

const handleUsernameChange = (data) => console.log(data);

const dataHandler = (incomingData: any) => {
  const { id } = incomingData;

  const user = users.find((id) => id === id);

  return user.username;
};

on('username-change', handleUsernameChange);
off('username-change', handleUsernameChange);
once('username-change', handleUsernameChange);
trigger('username-change', { username });
request('user-name-provider', { id: userId }, 'user-name', handleUsernameChange); // request only one time
respond('user-name', 'user-name-provider', dataHandler); // respond only one time.
broadcast('user-name', 'user-name-provider', dataHandler);

Readme

Keywords

none

Package Sidebar

Install

npm i @mertsolak/custom-event

Weekly Downloads

73

Version

1.0.2

License

MIT

Unpacked Size

9.18 kB

Total Files

11

Last publish

Collaborators

  • mertsolak