mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 03:11:56 +00:00
Rename anchor -> key globally ¯\_(ツ)_/¯
This commit is contained in:
parent
72223215cd
commit
8d2f19f062
@ -23,7 +23,7 @@ export class MessagesComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.websocketService.connect();
|
this.websocketService.connect();
|
||||||
this.websocketService.observeAnchor<Message>('message').subscribe(
|
this.websocketService.observeKey<Message>('message').subscribe(
|
||||||
(event) => {
|
(event) => {
|
||||||
this.messages.push(event.data);
|
this.messages.push(event.data);
|
||||||
event.data.message = this.convert(event.data.message);
|
event.data.message = this.convert(event.data.message);
|
||||||
|
@ -11,7 +11,7 @@ export class FSMUpdateService {
|
|||||||
constructor(private websocketService: WebSocketService) {}
|
constructor(private websocketService: WebSocketService) {}
|
||||||
|
|
||||||
public init(): void {
|
public init(): void {
|
||||||
this.websocketService.observeAnchor<FSMUpdate>('FSMUpdate').subscribe((event) => {
|
this.websocketService.observeKey<FSMUpdate>('FSMUpdate').subscribe((event) => {
|
||||||
this.current_state = event.data.current_state;
|
this.current_state = event.data.current_state;
|
||||||
this.valid_transitions = event.data.valid_transitions;
|
this.valid_transitions = event.data.valid_transitions;
|
||||||
});
|
});
|
||||||
|
@ -41,17 +41,17 @@ export class WebSocketService {
|
|||||||
console.log('ws connected');
|
console.log('ws connected');
|
||||||
}
|
}
|
||||||
|
|
||||||
public observeAnchor<T>(anchor: string): Observable<WSMessage<T>> {
|
public observeKey<T>(key: string): Observable<WSMessage<T>> {
|
||||||
return this.downlink.pipe(filter(message => message.anchor === anchor));
|
return this.downlink.pipe(filter(message => message.key === key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public send(anchor: string, data: any): void {
|
public send(key: string, data: any): void {
|
||||||
// If the WebSocket is not connected then the QueueingSubject will ensure
|
// If the WebSocket is not connected then the QueueingSubject will ensure
|
||||||
// that messages are queued and delivered when the WebSocket reconnects.
|
// that messages are queued and delivered when the WebSocket reconnects.
|
||||||
// A regular Subject can be used to discard messages sent when the WebSocket
|
// A regular Subject can be used to discard messages sent when the WebSocket
|
||||||
// is disconnected.
|
// is disconnected.
|
||||||
this.uplink.next({
|
this.uplink.next({
|
||||||
'anchor': anchor,
|
'key': key,
|
||||||
'data': data
|
'data': data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export class WSMessage<T> {
|
export class WSMessage<T> {
|
||||||
anchor: string;
|
key: string;
|
||||||
data: T; // TODO: sane annotation
|
data: T; // TODO: sane annotation
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ const defaultSourceCode = `alert( 'Hello, world!' );`;
|
|||||||
styleUrls: ['./webide.component.scss']
|
styleUrls: ['./webide.component.scss']
|
||||||
})
|
})
|
||||||
export class WebideComponent implements OnInit {
|
export class WebideComponent implements OnInit {
|
||||||
anchor_id = 'anchor_webide';
|
key_id = 'webide';
|
||||||
filename = 'demo.js';
|
filename = 'demo.js';
|
||||||
code: string = defaultSourceCode;
|
code: string = defaultSourceCode;
|
||||||
language = 'javascript';
|
language = 'javascript';
|
||||||
@ -47,7 +47,7 @@ export class WebideComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscribeWS() {
|
subscribeWS() {
|
||||||
this.webSocketService.observeAnchor<SourceCode>(this.anchor_id).subscribe((event) => {
|
this.webSocketService.observeKey<SourceCode>(this.key_id).subscribe((event) => {
|
||||||
this.command_handlers[event.data.command](event.data);
|
this.command_handlers[event.data.command](event.data);
|
||||||
this.changeDetectorRef.detectChanges();
|
this.changeDetectorRef.detectChanges();
|
||||||
});
|
});
|
||||||
@ -81,7 +81,7 @@ export class WebideComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendCode() {
|
sendCode() {
|
||||||
this.webSocketService.send(this.anchor_id, {
|
this.webSocketService.send(this.key_id, {
|
||||||
'command': 'write',
|
'command': 'write',
|
||||||
'content': this.code
|
'content': this.code
|
||||||
});
|
});
|
||||||
@ -89,13 +89,13 @@ export class WebideComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestCode() {
|
requestCode() {
|
||||||
this.webSocketService.send(this.anchor_id, {
|
this.webSocketService.send(this.key_id, {
|
||||||
'command': 'read'
|
'command': 'read'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
selectCode(filename: string) {
|
selectCode(filename: string) {
|
||||||
this.webSocketService.send(this.anchor_id, {
|
this.webSocketService.send(this.key_id, {
|
||||||
'command': 'select',
|
'command': 'select',
|
||||||
'filename': filename
|
'filename': filename
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user