mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 13:52:55 +00:00 
			
		
		
		
	Use templates for WSMessage
This commit is contained in:
		
				
					committed by
					
						
						Bálint Bokros
					
				
			
			
				
	
			
			
			
						parent
						
							d66705f2f2
						
					
				
				
					commit
					2c211daa3c
				
			@@ -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;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
export class WSMessage {
 | 
			
		||||
export class WSMessage<T> {
 | 
			
		||||
  anchor: string;
 | 
			
		||||
  data: any;  // TODO: sane annotation
 | 
			
		||||
  data: T;  // TODO: sane annotation
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user