@amatiasq/emitter

Collects listener for an event occurance.

Usage no npm install needed!

<script type="module">
  import amatiasqEmitter from 'https://cdn.skypack.dev/@amatiasq/emitter';
</script>

README

emitter

Collects listener for an event occurance.

Installation

Install with npm i --save @amatiasq/emitter.

Usage

import { emitter } from '@amatiasq/emitter';

const onNameChange = emitter<string>();
onNameChange.subscribe(value => console.log(`Received ${value}`));
onNameChange('My new name'); // Received My new name

Usage with channels

import { emitterWithChannels } from '@amatiasq/emitter';

const onNameChange = emitterWithChannels<string, number>();
onNameChange.subscribe('test', value => console.log(`Received ${value}`));
onNameChange('test', 10); // Received 10
onNameChange('foo', 10); // Nothing happens