0.0.1 • Published 8 years ago

chain-call v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

chain-call

Build a chain of method calls

Made with ❤ at @outlandish

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.