seedalpha / chainable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

seed-chainable

generic chainable interface as a lib

Installation

$ npm install seed-chainable --save

Usage

var chainable = require('seed-chainable');

var methods = ['find', 'limit', 'offset']
var context = {};

fuction onDone(ops, context, ...args) {
  console.log(ops, context, ...args);
  /**
   * [
   *   { method: 'find', args: [{ x: 5, y: 10 }] },
   *   { method: 'find', args: [{ z: 10 }] },
   *   { method: 'limit', args: [10] },
   *   { method: 'offset', args: [5] },
   * ],
   * {},
   * 'done!'
   */
}

var chain = chainable(methods, context, onDone);

chain = chain
  .find({ x: 5, y: 10 })
  .find({ z: 10 })
  .limit(10)
  .offset(5);

chain('done!');

Author

Vladimir Popov vlad@seedalpha.net

License

MIT

About


Languages

Language:JavaScript 100.0%