Postbus
Buffered message bus
Postbus is basic buffered message bus written in TypeScript. It runs in the browser, or on the server using node.js.
Setup
yarn add postbus
or
npm install --save postbus
Usage
Before you start import the library
Basic usage
// Setup a new bus with no bufferconst bus = // Data published can be anythingconst data = {}const message = 'Hi'const number = 1 // Setup a subscriberbus // Publish some databusbusbus // Cleanupbus
Buffered usage
// Setup a new bus with a buffer of 2 itemsconst bus = 2 // Data published can be anythingconst data = {}const message = 'Hi' // Publish before you subscribebusbus // Because this will exceed the buffer size, it will push the first item outbus // The subscription will go over all messages in the bufferbus // You can still pusblish here too, and the previous subscriber will catch it allbus // Cleanupbus