Asynchronous libraries wrapper
- PubSubJS - Dependency free publish/subscribe for JavaScript
- RSVP.js - A tiny implementation of Promises/A+ with deferred objects
$ npm install @absolunet/pinki
// Node.js
const pinki = require('@absolunet/pinki');
// Browser - Load vendor libraries
// - /node_modules/pubsub-js/src/pubsub.js
// - /node_modules/rsvp/dist/rsvp.js
const { pinki } = window;
// Messages
pinki.message.publish('alpha', 'Yeah!');
pinki.message.subscribe('alpha', (data) => {
console.log(data);
});
setTimeout(() => {
pinki.message.publish('alpha', 'Yessir!');
}, 100);
// Outputs:
// Yeah!
// Yessir!
pinki.vow.fulfill('gamma', 'Yeah!');
pinki.vow.when('gamma').then((data) => {
console.log(data);
});
pinki.vow.when(['gamma', 'delta']).then(([dataC, dataD]) => {
console.log(dataC, dataD);
});
setTimeout(() => {
pinki.vow.fulfill('delta', 'Yessir!');
}, 100);
// Outputs:
// 'Yeah!'
// { gamma:'Yeah!', delta:'Yessir!' }
Wraps PubSub.subscribe
, but also executes previously published messages that matches the subscription.
Type: Boolean
Default: true
Execute previously published messages.
Wraps PubSub.publish
.
Maps PubSub.unsubscribe
.
Vows are name-based Promises that can be referenced anytime.
Vows than have been registered.
Returns a Promise if one vow given or a RSVP.all
Promise which reacts when all vows are fulfilled or one is broken if multiple vows are given.
Type: String
or Array
One or multiple vow names
Resolve the underlying Promise.
Type: String
Vow name
Type: <any>
Data to resolve the underlying Promise with
Reject the underlying Promise.
Type: String
Vow name
Type: String
Error message to reject the underlying Promise with
MIT © Absolunet
“Pinky Finger” icon by Mitchell D. Eva from the Noun Project.