event-stream-pubsub

pubsub pattern for in-memory, stateless event streaming


Keywords
event, stream, pub, publish, sub, subscribe, pubsub, event stream, consume
Install
npm install event-stream-pubsub@0.1.3

Documentation

event-stream-pubsub

A simple wrapper around the EventEmitter, allowing us to speak in a pub/sub terms.

Supports in-memory, stateless event streaming out of the box.

installation

npm install --save event-stream-pubsub

usage

// define your event data-type
interface PhotoSelectedEvent {
  source: string;
  photo: {
    width: number;
    height: number;
    uri: string;
  };
}

// instantiate this particular stream
const photoSelectedEventStream = new EventStreamPubSub<PhotoSelectedEvent>();

// add a subscriber
const consumer = (event: PhotoSelectedEvent) => console.log(event);
photoSelectedEventStream.subscribe({ consumer });

// publish to the stream
const exampleEvent = {
  source: 'CAMERA_ROLL',
  photo: {
    width: 1000,
    height: 1000,
    uri: 'file://...',
  },
};
photoSelectedEventStream.publish(exampleEvent);