Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / src / internal / testing / ColdObservable.ts
1 import { Observable } from '../Observable';
2 import { Subscription } from '../Subscription';
3 import { Scheduler } from '../Scheduler';
4 import { TestMessage } from './TestMessage';
5 import { SubscriptionLog } from './SubscriptionLog';
6 import { SubscriptionLoggable } from './SubscriptionLoggable';
7 import { applyMixins } from '../util/applyMixins';
8 import { Subscriber } from '../Subscriber';
9
10 /**
11  * We need this JSDoc comment for affecting ESDoc.
12  * @ignore
13  * @extends {Ignored}
14  */
15 export 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 }
48 applyMixins(ColdObservable, [SubscriptionLoggable]);