Coder Social home page Coder Social logo

pinki's Introduction

pinki

pinki

npm npm dependencies npms Travis CI Code style ESLint

Pinky Promises

Asynchronous libraries wrapper

Dependencies / Implements

  • PubSubJS - Dependency free publish/subscribe for JavaScript
  • RSVP.js - A tiny implementation of Promises/A+ with deferred objects

Install

$ npm install @absolunet/pinki

Usage

// 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!' }

API - Messages

message.subscribe(topic, subscriber [, options])

Wraps PubSub.subscribe, but also executes previously published messages that matches the subscription.

options.executePrevious

Type: Boolean
Default: true
Execute previously published messages.

message.publish(topic, data)

Wraps PubSub.publish.

message.unsubscribe(topic|token)

Maps PubSub.unsubscribe.


API - Vows

Vows are name-based Promises that can be referenced anytime.

vow.list

Vows than have been registered.

vow.when(names)

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.

names

Type: String or Array
One or multiple vow names

vow.fulfill(name, data)

Resolve the underlying Promise.

name

Type: String
Vow name

data

Type: <any>
Data to resolve the underlying Promise with

vow.break(name, error)

Reject the underlying Promise.

name

Type: String
Vow name

error

Type: String
Error message to reject the underlying Promise with


License

MIT © Absolunet

Pinky Finger” icon by Mitchell D. Eva from the Noun Project.

pinki's People

Contributors

jblandry avatar

Stargazers

Thierry Parent avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.