Skip to content

Commit 61ee4ee

Browse files
committed
feat(MessageRecordObserver): rename VirtualObserver to MessageRecordObserver
1 parent 2b052a4 commit 61ee4ee

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

src/VirtualObserver.ts

-30
This file was deleted.

src/utils/MessageRecordObserver.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Rx from 'rxjs';
2+
import { TestMessageValue } from '../TestMessageValue';
3+
4+
/**
5+
* An Observer records Observable values emitted in form of TestMessageValue
6+
*
7+
*/
8+
export interface MessageRecordObserver<T = string> extends Rx.Observer<T> {
9+
/**
10+
* Metadata of subscribed Observable, recorded value of next(), error(), complete() calls.
11+
*/
12+
readonly messages: Readonly<Array<TestMessageValue<T>>>;
13+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as Rx from 'rxjs';
2+
import { Scheduler } from 'rxjs/Scheduler';
3+
import { TestMessageValue } from '../TestMessageValue';
4+
import { MessageRecordObserver } from './MessageRecordObserver';
5+
6+
class MessageRecordObserverBase<T = string> implements MessageRecordObserver<T> {
7+
public readonly messages: Readonly<Array<TestMessageValue<T>>> = [];
8+
9+
/**
10+
* Constructor.
11+
*
12+
* @param {() => number} nowMethod function returns current timeframe based on scheduler, as Scheduler::now() provides.
13+
*/
14+
constructor(private readonly nowMethod: typeof Scheduler.now) {
15+
}
16+
17+
next(value: T): void {
18+
this.messages.push(new TestMessageValue(this.nowMethod(), Rx.Notification.createNext(value)));
19+
}
20+
21+
error(value: any): void {
22+
this.messages.push(new TestMessageValue<any>(this.nowMethod(), Rx.Notification.createError(value)));
23+
}
24+
25+
complete(): void {
26+
this.messages.push(new TestMessageValue(this.nowMethod(), Rx.Notification.createComplete()));
27+
}
28+
}
29+
30+
const recordObserverFactory: (nowMethod: typeof Scheduler.now) => <T = string>() => MessageRecordObserver<T> =
31+
(nowMethod: typeof Scheduler.now) => <T = string>() => new MessageRecordObserverBase<T>(nowMethod);
32+
33+
export {
34+
recordObserverFactory
35+
};

0 commit comments

Comments
 (0)