import * as plugins from './smartrouter.plugins.js'; export interface ISelectionOption { key: string; detail: T; selected?: boolean; action: () => Promise; } export class SelectionDimension { /** * the key of the selection dimension */ public dimensionKey: string; /** * the level of the selection dimension * a higher level is execution later than a lower level * during catchup phase */ public dimensionLevel: number; public dimensionPeers: SelectionDimension[] = []; public selectionOptions: ISelectionOption[] = []; public selectionOptionSubject = new plugins.smartrx.rxjs.Subject[]>(); public async emitSelectionOptions () { const selectionOptions = this.selectionOptions.map((selectionOptionArg): ISelectionOption => { return { key: selectionOptionArg.key, detail: selectionOptionArg.detail, action: async () => { this.updateSelection(selectionOptionArg); return await selectionOptionArg.action(); }, } }); this.selectionOptionSubject.next(selectionOptions); } public async updateSelection (selectionOptionArg: ISelectionOption) { for (const selectionOption of this.selectionOptions) { if (selectionOption.key === selectionOptionArg.key) { selectionOption.selected = true; } else { selectionOption.selected = false; } } this.emitSelectionOptions(); } }