import { Decorator } from "./Decorator" ; import { DecoratorUtils } from "../../logic/utils/DecoratorUtils" ; export type ModifyFunction < ToModify extends Decorator > = ( original : ToModify ) => any ; export class Modifier < ToModify extends Decorator > extends Decorator { private _toModify : ModifyFunction < ToModify > ; private _modifyTypes : any [ ] ; protected constructor ( ) { super ( ) ; } static create < ToModify extends Decorator > ( toModify , ... modifyTypes ) { const modifier = new Modifier < ToModify > ( ) ; modifier . _toModify = toModify ; modifier . _modifyTypes = modifyTypes ; return modifier ; } param modifiers param originals returns static async applyFromModifierListToList ( modifiers , originals ) { return await Promise . all ( modifiers . map ( async ( modifier ) => { let linked = DecoratorUtils . getLinkedObjects ( modifier , originals ) ; linked = linked . filter ( ( l ) => modifier . _modifyTypes . includes ( ( l as Object ) . constructor ) ) ; await Promise . all ( linked . map ( async ( linkedOriginal ) => { return await modifier . applyModifications ( linkedOriginal ) ; } ) ) ; } ) ) ; } applyModifications ( original ) { return this . _toModify ( original ) ; } }