Use templates for WSMessage

This commit is contained in:
Bálint Bokros 2018-01-11 16:05:45 +01:00 committed by Bálint Bokros
parent d66705f2f2
commit 2c211daa3c
3 changed files with 6 additions and 6 deletions

View File

@ -19,7 +19,7 @@ export class TestButtonComponent implements OnInit {
}
ngOnInit() {
this.webSocketService.observeAnchor(this.anchor_id).subscribe((event) => {
this.webSocketService.observeAnchor<string>(this.anchor_id).subscribe((event) => {
this.text = event.data;
});
}

View File

@ -16,7 +16,7 @@ function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?
@Injectable()
export class WebSocketService {
private uplink: QueueingSubject<object>;
public downlink: Observable<WSMessage>;
public downlink: Observable<WSMessage<undefined>>;
constructor() {
@ -40,8 +40,8 @@ export class WebSocketService {
console.log('ws connected');
}
public observeAnchor(anchor: string): Observable<WSMessage> {
return this.downlink.filter(message => message.anchor === anchor);
public observeAnchor<T>(anchor: string): Observable<WSMessage<T>> {
return this.downlink.pipe(filter(message => message.anchor === anchor));
}
public send(anchor: string, data: any): void {

View File

@ -1,4 +1,4 @@
export class WSMessage {
export class WSMessage<T> {
anchor: string;
data: any; // TODO: sane annotation
data: T; // TODO: sane annotation
}