import { AbstractControl , AsyncValidatorFn } from "@angular/forms" ; import { Observable , of } from "rxjs" ; import { map } from 'rxjs/operators' ; import { APP_VALIDATORS } from '../../const/app-validators.const' ; import { FormProvider } from '../../util/form-provider' ; export function baseAsyncValidator ( configModel , validatorName ) { return ( control ) : Observable < { [ key ] : any ; } > => { configModel = configModel || { } ; if ( configModel . validatorConfig ) { if ( FormProvider . ProcessRule ( control , configModel ) ) { return ( < Observable < any > > configModel . validatorConfig ) . pipe ( map ( resolveConfig ( configModel , validatorName , control ) ) ) ; } return of ( null ) ; } else return of ( resolveConfig ( configModel , validatorName , control ) ( configModel ) ) ; } ; } function resolveConfig ( configModel , validatorName , control ) { return config => { let configClone = { ... configModel , ... config , ... { expressionProcessed : true } } ; return APP_VALIDATORS [ validatorName ] ( configClone ) ( control ) ; } ; }