2022-01-21 08:28:41 +00:00
|
|
|
import { Observable } from '../Observable';
|
|
|
|
import { Subscription } from '../Subscription';
|
|
|
|
import { SubscriptionLoggable } from './SubscriptionLoggable';
|
|
|
|
import { applyMixins } from '../util/applyMixins';
|
2022-06-08 10:36:39 +00:00
|
|
|
import { observeNotification } from '../Notification';
|
2022-01-21 08:28:41 +00:00
|
|
|
export class ColdObservable extends Observable {
|
|
|
|
constructor(messages, scheduler) {
|
|
|
|
super(function (subscriber) {
|
|
|
|
const observable = this;
|
|
|
|
const index = observable.logSubscribedFrame();
|
|
|
|
const subscription = new Subscription();
|
|
|
|
subscription.add(new Subscription(() => {
|
|
|
|
observable.logUnsubscribedFrame(index);
|
|
|
|
}));
|
|
|
|
observable.scheduleMessages(subscriber);
|
|
|
|
return subscription;
|
|
|
|
});
|
|
|
|
this.messages = messages;
|
|
|
|
this.subscriptions = [];
|
|
|
|
this.scheduler = scheduler;
|
|
|
|
}
|
|
|
|
scheduleMessages(subscriber) {
|
|
|
|
const messagesLength = this.messages.length;
|
|
|
|
for (let i = 0; i < messagesLength; i++) {
|
|
|
|
const message = this.messages[i];
|
2022-06-08 10:36:39 +00:00
|
|
|
subscriber.add(this.scheduler.schedule((state) => {
|
|
|
|
const { message: { notification }, subscriber: destination } = state;
|
|
|
|
observeNotification(notification, destination);
|
|
|
|
}, message.frame, { message, subscriber }));
|
2022-01-21 08:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applyMixins(ColdObservable, [SubscriptionLoggable]);
|
|
|
|
//# sourceMappingURL=ColdObservable.js.map
|