You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EventEmitter is a simple Event Emitter Implementation that is designed to be lightweight and simple.
Example
constemitter=newBottlecap.Emitter();lethealth=100;consthandleDamage=({ attacker, damageAmt })=>{health-=damageAmt;console.log(`You were attacked by ${attacker} and it caused -${damageAmt} damage to your health`);};emitter.on('damage',handleDamage);// subscribe to damage eventemitter.emit('damage',{attacker: "Goblin",damageAmt: 20});// emit damage eventemitter.once('damage',()=>console.log('First Damage'));emitter.off('damage',handleDamage);// unsubscribe to damage eventemitter.destroy();