import { RxFormGroup } from "../services/rx-form-group" ; import { FormGroupDirective } from "../directives/form-group.directive" ; export const formGroupContainer = new ( class { private formGroups : { [ key ] : RxFormGroup ; } = { } ; private groupKeyElements : { [ key ] : HTMLElement ; } = { } ; private formGroupDirectives : { [ key ] : FormGroupDirective ; } = { } ; get ( groupKey ) { return this . formGroups [ groupKey ] ; } saveFormGroup ( formGroup ) { let groupKey = formGroup . path ; this . formGroups [ formGroup . path ] = formGroup ; this . bindIt ( groupKey ) ; } mapElement ( groupKey , element ) { this . groupKeyElements [ groupKey ] = element ; this . bindIt ( groupKey ) ; } bindIt ( groupKey ) { if ( this . groupKeyElements [ groupKey ] && this . formGroups [ groupKey ] ) { setTimeout ( ( ) => { this . formGroupDirectives [ groupKey ] = new FormGroupDirective ( this . groupKeyElements [ groupKey ] , this . formGroups [ groupKey ] ) ; } , 100 ) ; } } destroy ( groupKey ) { if ( this . formGroupDirectives [ groupKey ] ) { this . formGroupDirectives [ groupKey ] . destroy ( ) ; delete this . formGroupDirectives [ groupKey ] ; } } } ) ( ) ;