/*! * devextreme-angular-test * Version: 17.2.8 * Build date: Mon Feb 05 2018 * * Copyright (c) 2012 - 2018 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-angular */ import { Injectable, SimpleChanges, IterableDiffers } from '@angular/core'; import { DxComponent } from './component'; @Injectable() export class IterableDifferHelper { private _host: DxComponent; private _propertyDiffers: { [id: string]: any; } = {}; constructor(private _differs: IterableDiffers) { } setHost(host: DxComponent) { this._host = host; } setup(prop: string, changes: SimpleChanges) { if (prop in changes) { const value = changes[prop].currentValue; this.setupSingle(prop, value); } } setupSingle(prop: string, value: any) { 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: string, value: any) { if (this._propertyDiffers[prop]) { return this._propertyDiffers[prop].diff(value); } } doCheck(prop: string) { if (this._propertyDiffers[prop]) { const changes = this.getChanges(prop, this._host[prop]); if (changes && this._host.instance) { this._host.lockWidgetUpdate(); this._host.instance.option(prop, this._host[prop]); } } } }