import StatusAction from "./StatusAction" ; import { computed , observable } from "mobx" ; export default class StatusActionQueue < T extends StatusAction > { @ observable private _queue : T [ ] = [ ] ; public add ( action ) { this . _queue . push ( action ) ; } public remove ( action ) { for ( let i = 0 ; i < this . _queue . length ; i ++ ) { if ( this . _queue [ i ] . key === action . key ) { this . _queue . splice ( i , 1 ) ; return ; } } console . error ( "Could not remove action: " + JSON . stringify ( action ) ) ; } returns public update ( action ) { const newQueue = new StatusActionQueue < T > ( ) ; for ( const element of this . _queue ) { if ( element . key === action . key ) { newQueue . add ( action ) ; } else { newQueue . add ( element ) ; } } return newQueue ; } public getAction ( key ) { for ( const element of this . _queue ) { if ( element . key === key ) { return element ; } } return undefined ; } @ computed public get isEmpty ( ) : boolean { return this . _queue . length === 0 ; } public [ Symbol . iterator ] ( ) { return this . _queue [ Symbol . iterator ] ( ) ; } }