import { IComponent , ComponentList , DirectiveList } from '../types' ; import { utils } from '../utils' ; import { ElementRef } from './element-ref' ; import { buildFoundMap } from './utils' ; param { IComponent } component returns { void } function buildViewChild ( component ) { if ( ! component . $viewChildList ) return ; component . $viewChildList . forEach ( ( { propertyName , selector } ) => { if ( typeof selector === 'string' ) { if ( component . $declarationMap . has ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( ! foundMap ) return ; const found = foundMap . find ( value => ( value . constructorFunction as any ) . selector === selector ) ; if ( found ) component [ propertyName ] = found . instanceScope ; } else { const findElementRef = component . $indivInstance . getRenderer . getElementByQuery ( selector , component . $nativeElement ) ; if ( findElementRef ) component [ propertyName ] = new ElementRef ( findElementRef ) ; } } if ( utils . isFunction ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( foundMap ) component [ propertyName ] = foundMap . find ( value => value . constructorFunction === selector ) . instanceScope ; } } ) ; } param { IComponent } component returns { void } function buildViewChildren ( component ) { if ( ! component . $viewChildrenList ) return ; component . $viewChildrenList . forEach ( ( { propertyName , selector } ) => { if ( typeof selector === 'string' ) { if ( component . $declarationMap . has ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( ! foundMap ) return ; component [ propertyName ] = ( foundMap as any [ ] ) . map ( value => { if ( ( value . constructorFunction as any ) . selector === selector ) return value . instanceScope ; } ) ; } else component [ propertyName ] = Array . from ( component . $indivInstance . getRenderer . getAllElementsByQuery ( selector , component . $nativeElement ) ) . map ( ( findElementRef ) => new ElementRef ( findElementRef ) ) ; } if ( utils . isFunction ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( foundMap ) component [ propertyName ] = ( foundMap as any [ ] ) . map ( value => { if ( value . constructorFunction === selector ) return value . instanceScope ; } ) ; } } ) ; } export param { IComponent } component export function buildViewChildandChildren ( component ) { buildViewChild ( component ) ; buildViewChildren ( component ) ; } export param { ( Function | string ) } selector returns { ( target : IComponent , propertyName : string ) => any } export function ViewChild ( selector ) { return function ( target , propertyName ) : any { if ( ! target . $viewChildList ) target . $viewChildList = [ ] ; target . $viewChildList . push ( { propertyName , selector } ) ; return target [ propertyName ] ; } ; } export param { ( Function | string ) } selector returns { ( target : IComponent , propertyName : string ) => any } export function ViewChildren ( selector ) { return function ( target , propertyName ) : any { if ( ! target . $viewChildrenList ) target . $viewChildrenList = [ ] ; target . $viewChildrenList . push ( { selector , propertyName } ) ; return target [ propertyName ] ; } ; }