HotObservable.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Subject } from '../Subject';
  2. import { Subscription } from '../Subscription';
  3. import { SubscriptionLoggable } from './SubscriptionLoggable';
  4. import { applyMixins } from '../util/applyMixins';
  5. import { observeNotification } from '../Notification';
  6. export class HotObservable extends Subject {
  7. constructor(messages, scheduler) {
  8. super();
  9. this.messages = messages;
  10. this.subscriptions = [];
  11. this.scheduler = scheduler;
  12. }
  13. _subscribe(subscriber) {
  14. const subject = this;
  15. const index = subject.logSubscribedFrame();
  16. const subscription = new Subscription();
  17. subscription.add(new Subscription(() => {
  18. subject.logUnsubscribedFrame(index);
  19. }));
  20. subscription.add(super._subscribe(subscriber));
  21. return subscription;
  22. }
  23. setup() {
  24. const subject = this;
  25. const messagesLength = subject.messages.length;
  26. for (let i = 0; i < messagesLength; i++) {
  27. (() => {
  28. const { notification, frame } = subject.messages[i];
  29. subject.scheduler.schedule(() => {
  30. observeNotification(notification, subject);
  31. }, frame);
  32. })();
  33. }
  34. }
  35. }
  36. applyMixins(HotObservable, [SubscriptionLoggable]);
  37. //# sourceMappingURL=HotObservable.js.map