import { Injectable , SimpleChanges , IterableDiffers } from '@angular/core' ; import { DxComponent } from './component' ; @ Injectable ( ) export class IterableDifferHelper { private _host : DxComponent ; private _propertyDiffers : { [ id ] : any ; } = { } ; constructor ( private _differs ) { } setHost ( host ) { this . _host = host ; } setup ( prop , changes ) { if ( prop in changes ) { const value = changes [ prop ] . currentValue ; this . setupSingle ( prop , value ) ; } } setupSingle ( prop , value ) { if ( value && Array . isArray ( value ) ) { if ( ! this . _propertyDiffers [ prop ] ) { try { this . _propertyDiffers [ prop ] = this . _differs . find ( value ) . create ( null ) ; return true ; } catch ( e ) { } } } else { delete this . _propertyDiffers [ prop ] ; } return false ; } getChanges ( prop , value ) { if ( this . _propertyDiffers [ prop ] ) { return this . _propertyDiffers [ prop ] . diff ( value ) ; } } checkChangedOptions ( propName , hostValue ) { return this . _host . changedOptions [ propName ] === hostValue ; } ; doCheck ( prop ) { if ( this . _propertyDiffers [ prop ] ) { let hostValue = this . _host [ prop ] , isChangedOption = this . checkChangedOptions ( prop , hostValue ) ; const changes = this . getChanges ( prop , hostValue ) ; if ( changes && this . _host . instance && ! isChangedOption ) { this . _host . lockWidgetUpdate ( ) ; this . _host . instance . option ( prop , hostValue ) ; } } } }