Skip to content

Instantly share code, notes, and snippets.

@JenHsuan
Created June 22, 2024 02:08
Show Gist options
  • Save JenHsuan/4f30630e4851e2f89bfcdad346a3808d to your computer and use it in GitHub Desktop.
Save JenHsuan/4f30630e4851e2f89bfcdad346a3808d to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements AfterViewInit{
protected undoConfigurationSubject = new BehaviorSubject<TopologyCommand | null>(null);
undoConfiguration$ = this.undoConfigurationSubject.asObservable();
protected resetConfigurationSubject = new BehaviorSubject<boolean | null>(null);
resetConfiguration$ = this.resetConfigurationSubject.asObservable();
..,
get isUndoButtonDisplayed(): boolean {
return this.commandStack.length > 0;
}
get undoButtonText() {
return `Undo (${this.commandStack.length})`;
}
protected onUndoButtonClicked() {
if (this.commandStack.length === 0) {
return;
}
this.undoConfigurationSubject.next(this.commandStack[0]);
}
protected onResetButtonClicked() {
const length = this.commandStack.length;
for (let i = 0; i < length; i++) {
this.commandStack.pop();
}
this.resetConfigurationSubject.next(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment