iterable-differ-helper.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. /*!
  3. * devextreme-angular
  4. * Version: 19.1.16
  5. * Build date: Tue Oct 18 2022
  6. *
  7. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  8. *
  9. * This software may be modified and distributed under the terms
  10. * of the MIT license. See the LICENSE file in the root of the project for details.
  11. *
  12. * https://github.com/DevExpress/devextreme-angular
  13. */
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. var core_1 = require("@angular/core");
  16. var IterableDifferHelper = (function () {
  17. function IterableDifferHelper(_differs) {
  18. this._differs = _differs;
  19. this._propertyDiffers = {};
  20. }
  21. IterableDifferHelper.prototype.setHost = function (host) {
  22. this._host = host;
  23. };
  24. IterableDifferHelper.prototype.setup = function (prop, changes) {
  25. if (prop in changes) {
  26. var value = changes[prop].currentValue;
  27. this.setupSingle(prop, value);
  28. }
  29. };
  30. IterableDifferHelper.prototype.setupSingle = function (prop, value) {
  31. if (value && Array.isArray(value)) {
  32. if (!this._propertyDiffers[prop]) {
  33. try {
  34. this._propertyDiffers[prop] = this._differs.find(value).create(null);
  35. return true;
  36. }
  37. catch (e) { }
  38. }
  39. }
  40. else {
  41. delete this._propertyDiffers[prop];
  42. }
  43. return false;
  44. };
  45. IterableDifferHelper.prototype.getChanges = function (prop, value) {
  46. if (this._propertyDiffers[prop]) {
  47. return this._propertyDiffers[prop].diff(value);
  48. }
  49. };
  50. IterableDifferHelper.prototype.checkChangedOptions = function (propName, hostValue) {
  51. return this._host.changedOptions[propName] === hostValue;
  52. };
  53. ;
  54. IterableDifferHelper.prototype.doCheck = function (prop) {
  55. if (this._propertyDiffers[prop]) {
  56. var hostValue = this._host[prop], isChangedOption = this.checkChangedOptions(prop, hostValue);
  57. var changes = this.getChanges(prop, hostValue);
  58. if (changes && this._host.instance && !isChangedOption) {
  59. this._host.lockWidgetUpdate();
  60. this._host.instance.option(prop, hostValue);
  61. }
  62. }
  63. };
  64. IterableDifferHelper.decorators = [
  65. { type: core_1.Injectable },
  66. ];
  67. /** @nocollapse */
  68. IterableDifferHelper.ctorParameters = function () { return [
  69. { type: core_1.IterableDiffers, },
  70. ]; };
  71. return IterableDifferHelper;
  72. }());
  73. exports.IterableDifferHelper = IterableDifferHelper;
  74. //# sourceMappingURL=iterable-differ-helper.js.map