mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 05:52:56 +00:00 
			
		
		
		
	Fix command callback delegation
This commit is contained in:
		@@ -32,25 +32,49 @@ export class WebideComponent implements OnInit {
 | 
			
		||||
  theme = 'monokai';
 | 
			
		||||
  files: string[];
 | 
			
		||||
  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,
 | 
			
		||||
              private changeDetectorRef: ChangeDetectorRef) { }
 | 
			
		||||
 | 
			
		||||
  ngOnInit() {
 | 
			
		||||
    this.subscribeWS();
 | 
			
		||||
    this.requestCode();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  subscribeWS() {
 | 
			
		||||
    this.webSocketService.observeAnchor<SourceCode>(this.anchor_id).subscribe((event) => {
 | 
			
		||||
      this.filename = event.data.filename;
 | 
			
		||||
      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.command_handlers[event.data.command](event);
 | 
			
		||||
      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();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  readHandler(event: any) {
 | 
			
		||||
    this.updateFileData(event);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  writeHandler(event: any) {
 | 
			
		||||
    this.saveButtonState = 'SAVED';
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setButtonStateDirty() {
 | 
			
		||||
    setTimeout(() => {this.saveButtonState = 'DIRTY'; }, 0);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user