mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 05:41:56 +00:00
Merge pull request #7 from avatao-content/reload_fix
Fix command callback delegation
This commit is contained in:
commit
95d616225f
@ -32,25 +32,49 @@ export class WebideComponent implements OnInit {
|
|||||||
theme = 'monokai';
|
theme = 'monokai';
|
||||||
files: string[];
|
files: string[];
|
||||||
saveButtonState = 'DIRTY';
|
saveButtonState = 'DIRTY';
|
||||||
|
command_handlers = { 'reload': this.reloadHandler.bind(this),
|
||||||
|
'read': this.readHandler.bind(this),
|
||||||
|
'select': this.selectHandler.bind(this),
|
||||||
|
'write': this.writeHandler.bind(this)};
|
||||||
|
|
||||||
constructor(private webSocketService: WebSocketService,
|
constructor(private webSocketService: WebSocketService,
|
||||||
private changeDetectorRef: ChangeDetectorRef) { }
|
private changeDetectorRef: ChangeDetectorRef) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.subscribeWS();
|
||||||
|
this.requestCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeWS() {
|
||||||
this.webSocketService.observeAnchor<SourceCode>(this.anchor_id).subscribe((event) => {
|
this.webSocketService.observeAnchor<SourceCode>(this.anchor_id).subscribe((event) => {
|
||||||
this.filename = event.data.filename;
|
this.command_handlers[event.data.command](event);
|
||||||
this.code = event.data.content;
|
|
||||||
this.language = modelist.getModeForPath(this.filename).name;
|
|
||||||
this.files = event.data.files;
|
|
||||||
|
|
||||||
if (event.data.command === 'write') { this.saveButtonState = 'SAVED'; }
|
|
||||||
if (event.data.command === 'reload') { this.requestCode(); }
|
|
||||||
|
|
||||||
this.changeDetectorRef.detectChanges();
|
this.changeDetectorRef.detectChanges();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFileData(event: any) {
|
||||||
|
this.filename = event.data.filename;
|
||||||
|
this.code = event.data.content;
|
||||||
|
this.language = modelist.getModeForPath(this.filename).name;
|
||||||
|
this.files = event.data.files;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectHandler(event: any) {
|
||||||
|
this.updateFileData(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadHandler(event: any) {
|
||||||
this.requestCode();
|
this.requestCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readHandler(event: any) {
|
||||||
|
this.updateFileData(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeHandler(event: any) {
|
||||||
|
this.saveButtonState = 'SAVED';
|
||||||
|
}
|
||||||
|
|
||||||
setButtonStateDirty() {
|
setButtonStateDirty() {
|
||||||
setTimeout(() => {this.saveButtonState = 'DIRTY'; }, 0);
|
setTimeout(() => {this.saveButtonState = 'DIRTY'; }, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user