Add tree navigation via arrow keys

This commit is contained in:
Thomas Nordquist
2019-06-25 01:39:31 +02:00
parent d054e64568
commit f4051b4cdf
9 changed files with 179 additions and 58 deletions

View File

@@ -3,22 +3,37 @@ import { EventDispatcher } from '../../../events'
export class TopicViewModel implements Destroyable {
private selected: boolean
public change = new EventDispatcher<void, TopicViewModel>()
private expanded: boolean
public selectionChange = new EventDispatcher<void, TopicViewModel>()
public expandedChange = new EventDispatcher<void, TopicViewModel>()
public constructor() {
this.selected = false
this.expanded = false
}
public destroy() {
this.change.removeAllListeners()
this.selectionChange.removeAllListeners()
}
public isSelected() {
return this.selected
}
public isExpanded() {
return this.expanded
}
public setSelected(selected: boolean) {
this.selected = selected
this.change.dispatch()
this.selectionChange.dispatch()
}
public setExpanded(expanded: boolean, fireEvent: boolean) {
const didChange = this.expanded !== expanded
this.expanded = expanded
if (didChange && fireEvent) {
this.expandedChange.dispatch()
}
}
}