5.1.2 • Published 3 years ago

pubbel v5.1.2

Weekly downloads
104
License
MIT
Repository
github
Last release
3 years ago

Pubbel

npm.io Node version NPM Downloads Minified size License: MIT

Pubbel is a light-weight JavaScript library around event-driven elements that can be used in front-end applications. It offers different usages for a publish-subscribe implemementation (wrapped as an event emitter), and an asynchronous queue that emits events.

Event Emitter

An event emitter can be created by using the emitter function.

import { emitter } from 'pubbel';
const _emitter = emitter();

You subscribe to a topic by using the on(topic: string, callback: Function) function. The callbacks can either be synchronous or asynchronous (NOTE: topic '*' is a wildcard topic that triggers on every emit).

function myFunction(...args) { ... }
_emitter.on('message-1', myFunction);
_emitter.off('message-1', myFunction);

Publishing a message on your emitter can be done by using the emit(topic, ...args) function.

_emitter.emit('message-2', data);

Broadcast channel

The broadcast channel can be used to synhronize data between browser tabs of running web applications. Synchronization is done via the localStorage (due to browser support). However, no data persists in the localStorage. As input, it requires a name and an optional configuration object. The available functions are the same as for the event emitter.

import { channel } from 'pubbel';

const myChannel = channel('my-channel');
myChannel.on('message-1', myCallback);
myChannel.emit('message-1', data);

Store

import { store } from 'pubbel';

const myStore = store({});
myStore.mutate('key', 1);
console.log(myStore.get('key')); // 1
console.log(myStore.get('key', (v) => v * 2)); // 2

myChannel.on('key', myCallback); // called on mutate
5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.0.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago