@cookiex/emitter
v1.0.5
Published
CookieX Emitter
Downloads
4
Readme
CX. Emitter
Install
yarn add @cookiex/emitter
or
npm install --save @cookiex/emitter
Usage
import Emitter from '@cookiex/emitter'
interface Events {
increment( value: number ): void
decrement( value: number ): void
}
const emitter = new Emitter<Events>()
let value = 0
emitter.on( 'increment', value => console.log( `++${value}` ) )
// ++1, ++2, ++3, ++4, ++5, ++6, ++7, ++8, ++9, ++10
emitter.on( 'decrement', value => console.log( `--${value}` ) )
// --9, --7, --6, --5, --4
emitter.once( 'decrement', value => value-- )
while( value < 10 ) emitter.emit( 'increment', value++ )
while( value >= 5 ) emitter.emit( 'decrement', value-- )
console.log( value ) // 4
License
CookieX Emitter is MIT licensed, as found in the LICENSE file