Skip to content

facing-dev/event-bus

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Read me

Event bus JavaScript implementation

Install

npm install --save @facing/event-bus

Usage

import EventBus from '@facing/event-bus'

const EB = new EventBus<{
    MyEvent: [string],
}>

//Listen
{
    EB.on('MyEvent', function (arg: string) { })
}

//Listen once
{
    EB.onOnce('MyEvent', function (arg: string) { })
}

//Delete listener
{
    function listener(arg: string) { }
    EB.on('MyEvent', listener)
    EB.off('MyEvent', listener)
}

//Delete listener by ListenerAgent
{
    const ListenerAgent = EB.on('MyEvent', function (arg: string) { })
    ListenerAgent.off()
}

//If ListenerAgent is an agent of a listener
{
    function listener(arg: string) { }
    const ListenerAgent = EB.on('MyEvent', listener)
    ListenerAgent.is(listener) //false
}

//Dispatch event
{
    EB.dispatch('MyEvent', 'value')
}

About

Event bus JavaScript implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published