@absolunet/pinki 中文文档教程

发布于 3年前 浏览 21 项目主页 更新于 3年前

pinki

pinki

npmnpm dependencies npms特拉维斯 CICode style ESLint

Pinky Promises

异步库包装器

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< /a>,但也执行与订阅匹配的先前发布的消息。

options.executePrevious

类型:布尔值
默认值:true
执行先前发布的消息。

message.publish(topic, data)

包装 PubSub.publish

message.unsubscribe(topic|token)

地图 PubSub.unsubscribe


API - Vows

誓言 是基于名字的承诺,可以随时引用。

vow.list

誓言比已登记。

vow.when(names)

如果给出一个誓言或 RSVP.all 则返回一个 Promise当所有誓言都得到履行时做出反应的承诺,或者如果给出多个誓言则一个誓言被打破。

names

类型:StringArray
一个或多个誓言名称

vow.fulfill(name, data)

Resolve 底层的 Promise。

name

类型:字符串
誓言名称

data

类型:
解析底层 Promise 和

vow.break(name, error)

Reject the underlying Promise 的数据。

name

类型:字符串
誓言名称

error

类型:String
拒绝底层 Promise 的错误消息


License

MIT © Absolunet

Pinky Finger” 图标由 Mitchell D. Eva 来自 名词项目

pinki

pinki

npmnpm dependenciesnpmsTravis CICode 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.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文