Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reactwaylabs/tiny-emitter
Small library to handle change emits.
https://github.com/reactwaylabs/tiny-emitter
change-emitter emitter tiny
Last synced: 8 days ago
JSON representation
Small library to handle change emits.
- Host: GitHub
- URL: https://github.com/reactwaylabs/tiny-emitter
- Owner: reactwaylabs
- License: mit
- Created: 2019-04-02T11:26:56.000Z (almost 6 years ago)
- Default Branch: dev
- Last Pushed: 2023-01-04T21:42:53.000Z (about 2 years ago)
- Last Synced: 2025-01-16T15:41:59.119Z (12 days ago)
- Topics: change-emitter, emitter, tiny
- Language: TypeScript
- Homepage:
- Size: 919 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version](https://img.shields.io/npm/v/@reactway/tiny-emitter.svg?logo=npm)](https://www.npmjs.com/package/@reactway/tiny-emitter)
[![Build Status](https://img.shields.io/azure-devops/build/reactway/reactway/6/master.svg?logo=azuredevops)](https://dev.azure.com/reactway/ReactWay/_build?definitionId=6)
[![Code coverage](https://img.shields.io/azure-devops/coverage/reactway/reactway/6/master.svg)](https://dev.azure.com/reactway/ReactWay/_build?definitionId=6)
[![Dependencies](https://img.shields.io/david/reactway/tiny-emitter.svg)](https://david-dm.org/reactway/tiny-emitter)
[![Dev dependencies](https://img.shields.io/david/dev/reactway/tiny-emitter.svg)](https://david-dm.org/reactway/tiny-emitter?type=dev)# @reactway/tiny-emitter
Small library to handle change emits.
## Get started
```sh
$ npm install @reactway/tiny-emitter
```## Example
```ts
type CounterHandler = (count: number) => void;
const handler: CounterHandler = count => console.log("Counter:", count);const counterEmitter = new TinyEmitter();
const removeListener = counterEmitter.addListener(handler);
counterEmitter.emit(1); // Emit change with value count=1
// Console log: Counter: 1removeListener(); // Remove registered listener
```## API
`.addListener(handler: Callback): () => void`
`.removeListener(handler: Callback): void`
`.emit(...payload: any): void`
`.getListenersCount(): number`
## License
Released under the [MIT license](LICENSE).