prain
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Prain

Tiny library to transform sequential function calls to method chaining.

Use cases

Use this library if you have many async methods and use it results one by one or if asynchronous and synchronous methods are interleaved and you don't want care about it.

Let's start with example.

const student = await StudentFactory.createStudentFromRemote(url, uid);
const chat = await student.getChat();
const message = await chat.createMessage();
await message.getFileUploader.upload(studingMaterialPath);
const success = await message.send();

We can write it as a chain using prain.

import _p from 'prain';

const success = await _p(StudentFactory)
  .createStudentFromRemote(url, uid)
  .getChat()
  .createMessage()
  .fileUploader // Note: syncronous access
  .upload(studingMaterialPath)
  .send();

Prain awaits all promises in the chain, no matter where they are – in properties, functions, methods.

See tests for more examples and use cases.

Made with love ❤️ and peace 🕊️.

/prain/

    Package Sidebar

    Install

    npm i prain

    Weekly Downloads

    2

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    9.72 kB

    Total Files

    9

    Last publish

    Collaborators

    • maxsior