Converts a bunch of functions into a method-chainable calss with a shared data model.
$ npm install model-chainify
Converts a bunch of functions into a method-chainable calss with a shared data model.
Don't care.
Any number of named functions or objects with methods. Note that functions can't be anonymous or will throw Error. All functions must take first argument as a data model object (or so called "object-based" functions) and return a (new) data model object.
A constructor with signature function (model)
. That can be invoked with new
operator to create an object with given model object. Objects created via the contructor owns all the mix-in functions plus a get()
method that returns the shared data model object.
Pass named functions:
var _ = require('lodash');
var chainify = require('model-chainify');
var Collection = chainify(_.flatten, _.uniq, _.sortBy);
var collection = new Collection([1, 2, [4, 3, 2]]);
collection.flatten().uniq().sortBy().get(); // => [1, 2, 3, 4]
Pass mix-ins Object:
var _ = require('lodash');
var chainify = require('model-chainify');
var Collection = chainify({
flatten: _.flatten,
unique: _.uniq,
sort: _.sortBy
});
var collection = new Collection([1, 2, [4, 3, 2]]);
collection.flatten().unique().sort().get(); // => [1, 2, 3, 4]
$ npm test
MIT