chain-call

0.0.1 • Public • Published

chain-call

Build a chain of method calls

Made with ❤ at @outlandish

npm version js-standard-style

Install

npm install --save chain-call
yarn add chain-call

Import

// ES6
import chainCall from 'chain-call'
 
// CommonJS
var chainCall = require('chain-call')

Example

const callApi = (entity, identifier) => chainCall(api, [
  entity,
  [typeof identifier === 'string' ? 'slug' : 'id', identifier],
  'get',
  ['then', (response) => response]
])
 
callApi('users', 59) // calls api.users().id(59).get().then((response) => response)

API

chainCall(subject, calls)

Chain call methods on an object.

  • subject {Object} Object to chain method calls on
  • calls {Array} Array of calls to chain

Returns the result of invoking each method in calls one-by-one on the return of the previous, beginning with a call on subject.

Contributing

All pull requests and issues welcome!

If you're not sure how, check out Kent C. Dodds' great video tutorials on egghead.io!

Author & License

chain-call was created by Sam Gluck and is released under the MIT license.

Package Sidebar

Install

npm i chain-call

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • sdgluck