1.0.2 • Published 9 years ago

call-chain v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

Method chain as an object

What it does?

It calls object methods and arguments represented as another object, with keys being methods names and values - methods arguments, replacing js native method chaining.

When is this useful?

This is useful when you want to put method chain in the db or transmit it using JSON.

Example

Init

var cc = require('call-chain')

Jquery

//original chain
$('<a>').
  attr('href', '#').
  addClass('btn btn-default')
//using cc
cc($('<a>'), {
  attr: {href: '#'},
  addClass: 'btn btn-default'
})

Underscore

var stooges = [
  {name: 'curly', age: 25},
  {name: 'moe', age: 21},
  {name: 'larry', age: 23}
]
//original chain
_.chain(stooges).
  sortBy(function(stooge) {return stooge.age}).
  map(function(stooge) {return stooge.name + ' is ' + stooge.age}).
  first().
  value()
//using cc
cc(_.chain(stooges), {
  sortBy: function(stooge) {return stooge.age},
  map: function(stooge) {return stooge.name + ' is ' + stooge.age},
  first: null,
  value: null
})

Moment

//original chain
moment().
  add({days: 1}).
  format('YYYY-MM-DD hh:mm:ss')
//using cc
cc(moment(), {
  add: {days: 1},
  format: 'YYYY-MM-DD hh:mm:ss'
})
1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago