source: trip-planner-front/node_modules/rxjs/src/internal/testing/ColdObservable.ts@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import { Observable } from '../Observable';
2import { Subscription } from '../Subscription';
3import { Scheduler } from '../Scheduler';
4import { TestMessage } from './TestMessage';
5import { SubscriptionLog } from './SubscriptionLog';
6import { SubscriptionLoggable } from './SubscriptionLoggable';
7import { applyMixins } from '../util/applyMixins';
8import { Subscriber } from '../Subscriber';
9
10/**
11 * We need this JSDoc comment for affecting ESDoc.
12 * @ignore
13 * @extends {Ignored}
14 */
15export class ColdObservable<T> extends Observable<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(function (this: Observable<T>, subscriber: Subscriber<any>) {
24 const observable: ColdObservable<T> = this as any;
25 const index = observable.logSubscribedFrame();
26 const subscription = new Subscription();
27 subscription.add(new Subscription(() => {
28 observable.logUnsubscribedFrame(index);
29 }));
30 observable.scheduleMessages(subscriber);
31 return subscription;
32 });
33 this.scheduler = scheduler;
34 }
35
36 scheduleMessages(subscriber: Subscriber<any>) {
37 const messagesLength = this.messages.length;
38 for (let i = 0; i < messagesLength; i++) {
39 const message = this.messages[i];
40 subscriber.add(
41 this.scheduler.schedule(({ message, subscriber }) => { message.notification.observe(subscriber); },
42 message.frame,
43 { message, subscriber })
44 );
45 }
46 }
47}
48applyMixins(ColdObservable, [SubscriptionLoggable]);
Note: See TracBrowser for help on using the repository browser.