UNPKG

@syncfusion/ej2-ng-base

Version:

A common package of Essential JS 2 base Angular libraries, methods and class definitions

122 lines (121 loc) 4.57 kB
import { getValue, setValue } from '@syncfusion/ej2-base'; import { clearTemplate } from './util'; var ComplexBase = /** @class */ (function () { function ComplexBase() { this.hasChanges = false; this.propCollection = {}; this.tags = []; this.tagObjects = []; } ComplexBase.prototype.ngOnInit = function () { this.registeredTemplate = {}; for (var _i = 0, _a = this.tags; _i < _a.length; _i++) { var tag = _a[_i]; var objInstance = getValue('child' + tag.substring(0, 1).toUpperCase() + tag.substring(1), this); if (objInstance) { this.tagObjects.push({ instance: objInstance, name: tag }); } } var templateProperties = Object.keys(this); templateProperties = templateProperties.filter(function (val) { return /Ref$/i.test(val); }); for (var _b = 0, templateProperties_1 = templateProperties; _b < templateProperties_1.length; _b++) { var tempName = templateProperties_1[_b]; var propName = tempName.replace('Ref', ''); setValue(propName.replace('_', '.'), getValue(propName, this), this.propCollection); } }; ComplexBase.prototype.ngOnChanges = function (changes) { for (var _i = 0, _a = Object.keys(changes); _i < _a.length; _i++) { var propName = _a[_i]; var changedVal = changes[propName]; this.propCollection[propName] = changedVal.currentValue; } this.hasChanges = true; }; ComplexBase.prototype.clearTemplate = function (templateNames) { clearTemplate(this, templateNames); }; ; ComplexBase.prototype.getProperties = function () { for (var _i = 0, _a = this.tagObjects; _i < _a.length; _i++) { var tagObject = _a[_i]; this.propCollection[tagObject.name] = tagObject.instance.getProperties(); } return this.propCollection; }; ComplexBase.prototype.isChanged = function () { var result = this.hasChanges; for (var _i = 0, _a = this.tagObjects; _i < _a.length; _i++) { var item = _a[_i]; result = result || item.instance.hasChanges; } return result; }; ComplexBase.prototype.ngAfterContentChecked = function () { this.hasChanges = this.isChanged(); var templateProperties = Object.keys(this); templateProperties = templateProperties.filter(function (val) { return /Ref$/i.test(val); }); }; ComplexBase.prototype.ngAfterViewChecked = function () { this.hasChanges = false; }; return ComplexBase; }()); export { ComplexBase }; var ArrayBase = /** @class */ (function () { function ArrayBase(propertyName) { this.list = []; this.hasChanges = false; this.propertyName = propertyName; } ArrayBase.prototype.ngOnInit = function () { this.isInitChanges = true; }; ArrayBase.prototype.ngAfterContentInit = function () { var _this = this; var index = 0; this.list = this.children.map(function (child) { child.index = index++; child.property = _this.propertyName; return child; }); this.hasChanges = true; }; ArrayBase.prototype.getProperties = function () { var onlyProp = []; for (var _i = 0, _a = this.list; _i < _a.length; _i++) { var item = _a[_i]; onlyProp.push(item.getProperties()); } return onlyProp; }; ArrayBase.prototype.isChanged = function () { var result = false; for (var _i = 0, _a = this.list; _i < _a.length; _i++) { var item = _a[_i]; result = result || item.hasChanges; } return !!this.list.length && result; }; ArrayBase.prototype.clearTemplate = function (templateNames) { var _this = this; for (var _i = 0, _a = this.list; _i < _a.length; _i++) { var item = _a[_i]; item.clearTemplate(templateNames && templateNames.map(function (val) { return new RegExp(_this.propertyName).test(val) ? val.replace(_this.propertyName + '.', '') : val; })); } }; ArrayBase.prototype.ngAfterContentChecked = function () { this.hasChanges = this.isChanged(); }; ArrayBase.prototype.ngAfterViewInit = function () { this.isInitChanges = false; }; return ArrayBase; }()); export { ArrayBase };