timeInterval.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var Subscriber_1 = require('../Subscriber');
  8. var async_1 = require('../scheduler/async');
  9. function timeInterval(scheduler) {
  10. if (scheduler === void 0) { scheduler = async_1.async; }
  11. return function (source) { return source.lift(new TimeIntervalOperator(scheduler)); };
  12. }
  13. exports.timeInterval = timeInterval;
  14. var TimeInterval = (function () {
  15. function TimeInterval(value, interval) {
  16. this.value = value;
  17. this.interval = interval;
  18. }
  19. return TimeInterval;
  20. }());
  21. exports.TimeInterval = TimeInterval;
  22. ;
  23. var TimeIntervalOperator = (function () {
  24. function TimeIntervalOperator(scheduler) {
  25. this.scheduler = scheduler;
  26. }
  27. TimeIntervalOperator.prototype.call = function (observer, source) {
  28. return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler));
  29. };
  30. return TimeIntervalOperator;
  31. }());
  32. /**
  33. * We need this JSDoc comment for affecting ESDoc.
  34. * @ignore
  35. * @extends {Ignored}
  36. */
  37. var TimeIntervalSubscriber = (function (_super) {
  38. __extends(TimeIntervalSubscriber, _super);
  39. function TimeIntervalSubscriber(destination, scheduler) {
  40. _super.call(this, destination);
  41. this.scheduler = scheduler;
  42. this.lastTime = 0;
  43. this.lastTime = scheduler.now();
  44. }
  45. TimeIntervalSubscriber.prototype._next = function (value) {
  46. var now = this.scheduler.now();
  47. var span = now - this.lastTime;
  48. this.lastTime = now;
  49. this.destination.next(new TimeInterval(value, span));
  50. };
  51. return TimeIntervalSubscriber;
  52. }(Subscriber_1.Subscriber));
  53. //# sourceMappingURL=timeInterval.js.map