SkipOp.js 661 B

12345678910111213141516171819202122232425
  1. var Op = require("../Op");
  2. /** The $skip operator; opts is the number of Objects to skip. **/
  3. var SkipOp = module.exports = (function(){
  4. // CONSTRUCTOR
  5. var base = Op, proto, klass = function SkipOp(opts){
  6. this.n = 0;
  7. base.call(this, opts);
  8. };
  9. proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  10. // PROTOTYPE MEMBERS
  11. proto.write = function writeUnlessSkipped(obj){
  12. //console.debug("$skip write:", {opIndex:this.idx, skip:this.opts, n:this.n, isSkip:(this.n < this.opts), obj:obj});
  13. if(this.n++ >= this.opts)
  14. this.queue(obj);
  15. };
  16. proto.reset = function resetSkipper(){
  17. this.n = 0;
  18. };
  19. return klass;
  20. })();