event-stream-pubsub
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

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

/event-stream-pubsub/

    Package Sidebar

    Install

    npm i event-stream-pubsub

    Weekly Downloads

    229

    Version

    0.1.3

    License

    none

    Unpacked Size

    11.7 kB

    Total Files

    8

    Last publish

    Collaborators

    • uladkasach