import { GeneralTask } from "./GeneralTask" ; export class GeneralProcess < TThis , TArgs extends any [ ] > { thisArg : TThis ; tasks : GeneralTask [ ] ; enabled : boolean = true ; constructor ( thisArg ) { this . thisArg = thisArg ; this . tasks = [ ] ; } process ( source = this . thisArg , ... args ) { if ( this . enabled ) { this . tasks . forEach ( task => { task . run ( this . thisArg , source , ... args ) ; } ) ; } return this ; } before ( action , identifier ? ) { action && this . tasks . unshift ( new GeneralTask ( action , identifier ) ) ; return this ; } next ( action , identifier ? ) { action && this . tasks . push ( new GeneralTask ( action , identifier ) ) ; return this ; } remove ( identifier ? ) { const tasks = this . tasks . filter ( v => v . identifier === identifier ) ; tasks . forEach ( task => { const index = this . tasks . indexOf ( task ) ; if ( index >= 0 ) { this . tasks . splice ( index , 1 ) ; } } ) ; return this ; } clear ( ) { this . tasks = [ ] ; return this ; } enable ( ) { this . enabled = true ; return this ; } disable ( ) { this . enabled = false ; return this ; } }