New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

eventbus-ts

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventbus-ts

EventBus written in Typescript.

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Build Status npm version

TypeScript Event Bus

EventBus written in Typescript. Events are typed!

Installation

npm install eventbus-ts

Usage

Importing EventBus and Event

import {EventBus, Subscribe} from "eventbus-ts";

Creating Events

Create Event(s) with the specified type, i.e, string, number, etc.

class DataEvent extends EventBus.Event<string> {}
class NumEvent extends EventBus.Event<number> {}

Overwrite getData() if you need to custom process your data. Ex:

class DisconnectEvent extends EventBus.Event<string> {
    getData(): string {
        return 'Disconnecting... ' + this.data;
    }
}

Register with EventBus

Register for Events with EventBus.getDefault().register(this).

Use Subscribe Decorator

Subscribe to events using @Subscribe('EVENT_NAME') for example:

@Subscribe('DataEvent')
onDataEvent(data: string) : void {
    /* process data from DataEvent */
}

Usage Sample

class Activity {
    constructor() {
        EventBus.getDefault().register(this);
    }

    @Subscribe('DataEvent')
    onDataEvent(data: string) : void {
        /* process data from DataEvent */
    }

    @Subscribe('NumEvent')
    onNumEvent(data: number): void {
        /* process data from NumEvent */
    }
}

Posting Events

To send events call the post() method for the Event:

EventBus.getDefault().post(new DataEvent('sync up!'));
EventBus.getDefault().post(new NumEvent(299792458));

License

MIT License

Keywords

typescript

FAQs

Package last updated on 02 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts