ColdObservable.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 Observable_1 = require('../Observable');
  8. var Subscription_1 = require('../Subscription');
  9. var SubscriptionLoggable_1 = require('./SubscriptionLoggable');
  10. var applyMixins_1 = require('../util/applyMixins');
  11. /**
  12. * We need this JSDoc comment for affecting ESDoc.
  13. * @ignore
  14. * @extends {Ignored}
  15. */
  16. var ColdObservable = (function (_super) {
  17. __extends(ColdObservable, _super);
  18. function ColdObservable(messages, scheduler) {
  19. _super.call(this, function (subscriber) {
  20. var observable = this;
  21. var index = observable.logSubscribedFrame();
  22. subscriber.add(new Subscription_1.Subscription(function () {
  23. observable.logUnsubscribedFrame(index);
  24. }));
  25. observable.scheduleMessages(subscriber);
  26. return subscriber;
  27. });
  28. this.messages = messages;
  29. this.subscriptions = [];
  30. this.scheduler = scheduler;
  31. }
  32. ColdObservable.prototype.scheduleMessages = function (subscriber) {
  33. var messagesLength = this.messages.length;
  34. for (var i = 0; i < messagesLength; i++) {
  35. var message = this.messages[i];
  36. subscriber.add(this.scheduler.schedule(function (_a) {
  37. var message = _a.message, subscriber = _a.subscriber;
  38. message.notification.observe(subscriber);
  39. }, message.frame, { message: message, subscriber: subscriber }));
  40. }
  41. };
  42. return ColdObservable;
  43. }(Observable_1.Observable));
  44. exports.ColdObservable = ColdObservable;
  45. applyMixins_1.applyMixins(ColdObservable, [SubscriptionLoggable_1.SubscriptionLoggable]);
  46. //# sourceMappingURL=ColdObservable.js.map