@reactway/tiny-emitter
v1.0.2
Published
Small change emitter
Downloads
4
Readme
@reactway/tiny-emitter
Small library to handle change emits.
Get started
$ npm install @reactway/tiny-emitter
Example
type CounterHandler = (count: number) => void;
const handler: CounterHandler = count => console.log("Counter:", count);
const counterEmitter = new TinyEmitter<CounterHandler>();
const removeListener = counterEmitter.addListener(handler);
counterEmitter.emit(1); // Emit change with value count=1
// Console log: Counter: 1
removeListener(); // Remove registered listener
API
.addListener(handler: Callback): () => void
.removeListener(handler: Callback): void
.emit(...payload: any): void
.getListenersCount(): number
License
Released under the MIT license.