1 | import { Subject } from '../Subject';
|
---|
2 | import { Subscriber } from '../Subscriber';
|
---|
3 | import { Subscription } from '../Subscription';
|
---|
4 | import { Scheduler } from '../Scheduler';
|
---|
5 | import { TestMessage } from './TestMessage';
|
---|
6 | import { SubscriptionLog } from './SubscriptionLog';
|
---|
7 | import { SubscriptionLoggable } from './SubscriptionLoggable';
|
---|
8 | import { applyMixins } from '../util/applyMixins';
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * We need this JSDoc comment for affecting ESDoc.
|
---|
12 | * @ignore
|
---|
13 | * @extends {Ignored}
|
---|
14 | */
|
---|
15 | export class HotObservable<T> extends Subject<T> implements SubscriptionLoggable {
|
---|
16 | public subscriptions: SubscriptionLog[] = [];
|
---|
17 | scheduler: Scheduler;
|
---|
18 | logSubscribedFrame: () => number;
|
---|
19 | logUnsubscribedFrame: (index: number) => void;
|
---|
20 |
|
---|
21 | constructor(public messages: TestMessage[],
|
---|
22 | scheduler: Scheduler) {
|
---|
23 | super();
|
---|
24 | this.scheduler = scheduler;
|
---|
25 | }
|
---|
26 |
|
---|
27 | /** @deprecated This is an internal implementation detail, do not use. */
|
---|
28 | _subscribe(subscriber: Subscriber<any>): Subscription {
|
---|
29 | const subject: HotObservable<T> = this;
|
---|
30 | const index = subject.logSubscribedFrame();
|
---|
31 | const subscription = new Subscription();
|
---|
32 | subscription.add(new Subscription(() => {
|
---|
33 | subject.logUnsubscribedFrame(index);
|
---|
34 | }));
|
---|
35 | subscription.add(super._subscribe(subscriber));
|
---|
36 | return subscription;
|
---|
37 | }
|
---|
38 |
|
---|
39 | setup() {
|
---|
40 | const subject = this;
|
---|
41 | const messagesLength = subject.messages.length;
|
---|
42 | /* tslint:disable:no-var-keyword */
|
---|
43 | for (var i = 0; i < messagesLength; i++) {
|
---|
44 | (() => {
|
---|
45 | var message = subject.messages[i];
|
---|
46 | /* tslint:enable */
|
---|
47 | subject.scheduler.schedule(
|
---|
48 | () => { message.notification.observe(subject); },
|
---|
49 | message.frame
|
---|
50 | );
|
---|
51 | })();
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 | applyMixins(HotObservable, [SubscriptionLoggable]);
|
---|