Skip to content

jaehwan-moon/chainify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chainify

Make functions of an instance chainable

How to use Chainify

const chainify = require('@cokencode/chainify');

// An example instance
const calculator = {
  addOne: number => number + 1
  multiplyByTwo: number => number * 2
  addOnePromise: number => Promise.resolve(number + 1)
};

const chainableCaluculator = chainify(calculator, 3);

chainableCalculator
  .addOne()
  .multiplyByTwo()
  .multiplyByTwo()
  .addOne()
  .unwrapChainify()
  .then(result => console.log(result));

API

  • chainify(instance, initialValue)

    • instance: Any object whose methods will be able to be chained.
    • initialValue (optional): The value that is passed to a first function chained as an parameter
  • unwrapChainify(): This method can be called in a chain in order get a result value. It returns Promise. Warning: After calling this function, methods can no longer be chained.

About

Make methods chainable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published