mixit/src/helpers/lists/Selectable.ts

29 lines
448 B
TypeScript

export class Selectable<T> {
protected selectedId = 0
constructor(public data: T[]){ }
get selected(): T | undefined {
return this.data[this.selectedId]
}
get selectedKey() {
return this.selectedId
}
select(key: number) {
this.selectedId = key
}
isSelected(key: number) {
return this.selectedId === key
}
remove() {
this.data.splice(this.selectedId, 1)
this.selectedId = 0
return this
}
}