import { TelemetryService } from '../services/telemetry.service' ; import { Action } from './Action' ; import { of , throwError , Observable } from 'rxjs' ; export class ActionCollection { public collection : Action [ ] = [ ] ; constructor ( private telemetry ) { } public runWithTelemetry ( action , source ) { if ( ! action . canRun || action . running ) { return of ( true ) ; } this . runInternal ( action , source ) . subscribe ( ) ; } public get length ( ) : number { return this . collection . length ; } public add ( action ) { this . collection . push ( action ) ; } public get anyRunning ( ) : boolean { return this . collection . some ( action => action . running ) ; } public get title ( ) : string { const runningAction = this . collection . find ( a => a . running ) ; if ( runningAction ) { return runningAction . runningTitle ; } else { return 'Actions' ; } } private runInternal ( action , source ) { const params = [ ( result ) => { } , ( reason ) => { const result = reason && reason . statusText && reason . status && reason . status + ': ' + reason . statusText || false ; return throwError ( reason ) ; } ] ; return action . runWithCallbacks . apply ( action , params ) ; } }