Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vorillaz/tabsub
A tiny Pub/Sub library for modern browsers.
https://github.com/vorillaz/tabsub
Last synced: about 1 month ago
JSON representation
A tiny Pub/Sub library for modern browsers.
- Host: GitHub
- URL: https://github.com/vorillaz/tabsub
- Owner: vorillaz
- License: mit
- Created: 2019-04-04T12:08:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-19T17:08:52.000Z (over 5 years ago)
- Last Synced: 2025-01-06T21:35:29.150Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Tabsub 📻
A tiny (~500B) Pub/Sub library that simply works
## Intro
Tabsub is a tiny library with minimal API that allows simple communication between browsing contexts with the same origin. It works with the BroadcastChannel API with a sensible fallback to localStorage, thus it works with all modern browsers.
## Installation
Install Tabsub from the NPM registry as:
```
npm install --save tabsub
```## Usage
### Create a channel and send a message
```javascript
import tabsub from 'tabsub';const radio = tabsub('channel-name');
radio.post('One message');
radio.post({msg: 'Another one'});
```### Create a channel start listening for incoming messages
```javascript
import tabsub from 'tabsub';const radio = tabsub('channel-name');
r.on(msg => {
console.log(`Message received: ${msg} `);
});
```### Pause and restart a channel
```javascript
import tabsub from 'tabsub';const radio = tabsub('channel-name');
// Posting
radio.post('One message');
radio.stop();radio.post('Ignored');
radio.start();
radio.post('Keep them coming');
```## Browser support
All modern browsers using the [BroadcastChannel API](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel) and the [localStorage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)