typescript-pubsub
v0.0.3
Published
Simple implementation of Publisher-Subscriber pattern in typescript
Maintainers
Readme
TypeScript implementation of publisher-subscriber pattern
Installation
npm install typescript-pubsubor
git clone https://github.com/vbrdnk/typescirpt-pubSub.gitUsage
import { PubSub } from 'your_relative_path_to_package';Use available static methods for subscribing, unsubscribing and emitting events from PubSub class
API
List of all available methods:
public static subscribe(eventName: string, callbackFunc: Function): voidAddseventName: Function[]property tostatic eventsobject and pushescallbackFuncto this array.public static unsubcribe(eventName: string, callbackFunc: Function): voidChecks for eventName property instatic eventsand if exits checks for all functions listed in this property. If callback function exists in an array, removes it, so it won't be execudedpublic static emit(eventName: string, data: any): voidChecks for eventName property instatic eventsand executes all functions inside eventName property with given data
Other methods and properties:
private static events: {}Holds all events that are added withPubSub.subscribe(eventName: string, callbackFunc: Function): voidmethod as well as all functions that should be executed when some data is emitted with specific event
