import { computed , isObservable , observable } from "mobx" ; import Metric from "./Metric" ; export default class MetricSet { @ observable private metrics : Metric [ ] ; public constructor ( metrics ) { if ( ! isObservable ( metrics ) ) { metrics = observable ( metrics ) ; } this . metrics = metrics ; } public addMetric ( metric ) { this . metrics . push ( metric ) ; } public addMetrics ( metrics ) { this . metrics = this . metrics . concat ( metrics ) ; } @ computed get length ( ) : number { return this . metrics . length ; } @ computed get keys ( ) : string [ ] { return this . metrics . map ( ( m ) => m . id ) ; } @ computed get asSelectOptions ( ) : SelectOptionValue [ ] { return this . metrics ; } public getMetricByKey ( sourceId ) { if ( ! sourceId ) { return ; } for ( const metric of this . metrics ) { if ( metric . id === sourceId ) { return metric ; } } } }