0.0.1 • Published 6 years ago

@botorjs/event-bus v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Event Bus

Build Status Coverage Status

Library that core of Botorjs is a event bus

Installation

npm install @botorjs/event-bus --save

Setup and Example

    import { EventBus } from "../src/EventBus";
    var bus: EventBus = new EventBus();

    // 
    bus.on("test", function(data) {
       // process
    })
    bus.emit("test", "test");

    // channel point-to-point
    bus.registerChannel("test", "test", (data: ContextChannel) => {
        // process
    });
    bus.emit("test","t");
    bus.emit("test","t");
    bus.emit("test","t");

API

EventBus

PropertyDescription
on(name, callback)listen event
once(name, callback)listen event one time
off(name, callback)remove listen event
registerChannel(name, event_name, callback, limit = 0)register a channel with callback handle
getChannel(name)get channel have register
removeChannel(name)remove channel have register

ContextChannel

  • data connext of Channel
PropertyDescription
dataget value data
channelset channel event

Channel

PropertyDescription
namename channel
listenlisten event
removeremove listen event