import { Value } from '@/models/Value' ; interface Data { values : Value [ ] ; limit ? : { min ? : Value ; max ? : Value ; } ; } export interface StateDto extends Data { } export type ChangeLimitCommand = { min ? : Value ; max ? : Value ; } ; /**
 * State object stores information about values, and limits,
 * and any other values, that can be dynamically changed in the system.
 */ export class State { public readonly values : Value [ ] ; public readonly limit ? : { min ? : Value ; max ? : Value ; } ; private constructor ( ctor ) { this . values = ctor . values ; this . limit = ctor . limit ; } public updateValues ( values ) { return new State ( { ... this . toData ( ) , values , } ) ; } public changeLimit ( command ) { return new State ( { ... this . toData ( ) , limit : command , } ) ; } /**
     * If value exists (by instance) in @state, and doesn't exist in this.state,
     * it is marked as changed.
     */ public findChangedValues ( state ) { return state . values . reduce ( ( changedValues , value , index ) => { if ( this . values . includes ( value ) ) { return changedValues ; } else { return changedValues . concat ( index ) ; } } , [ ] as number [ ] ) . sort ( ) ; } public static fromData ( data ) { return new State ( data ) ; } public toDto ( ) { return this . toData ( ) ; } private toData ( ) { return { values : this . values , limit : this . limit , } ; } }