Skip to content

pubsub pattern for in-memory, stateless event streaming

Notifications You must be signed in to change notification settings

ehmpathy/event-stream-pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);