LastAccumulator.js 900 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. /**
  3. * Accumulator for getting last value
  4. * @class LastAccumulator
  5. * @namespace mungedb-aggregate.pipeline.accumulators
  6. * @module mungedb-aggregate
  7. * @constructor
  8. **/
  9. var LastAccumulator = module.exports = function LastAccumulator(){
  10. if (arguments.length !== 0) throw new Error("zero args expected");
  11. this.reset();
  12. base.call(this);
  13. }, klass = LastAccumulator, base = require("./Accumulator"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  14. proto.processInternal = function processInternal(input, merging) {
  15. // always remember the last value seen
  16. this._last = input;
  17. };
  18. proto.getValue = function getValue(toBeMerged) {
  19. return this._last;
  20. };
  21. proto.reset = function reset() {
  22. this._last = undefined;
  23. };
  24. klass.create = function create() {
  25. return new LastAccumulator();
  26. };
  27. proto.getOpName = function getOpName(){
  28. return "$last";
  29. };