From dba96060666a929eb616bcacb492f6f5f3f56106 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 24 Oct 2023 19:36:00 -0400 Subject: [PATCH] fix(common): make sure destroy is a function before calling it (#1148) * fix(common): make sure destroy is a function before calling it * fix(common): make sure destroy is a function before calling it --------- Co-authored-by: ghiscoding --- packages/common/src/editors/autocompleterEditor.ts | 4 +++- packages/common/src/editors/dateEditor.ts | 2 +- packages/common/src/editors/selectEditor.ts | 4 +++- packages/common/src/filters/autocompleterFilter.ts | 4 +++- packages/common/src/filters/selectFilter.ts | 4 +++- packages/common/src/services/filter.service.ts | 4 +++- .../src/components/slick-vanilla-grid-bundle.ts | 6 ++++-- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/common/src/editors/autocompleterEditor.ts b/packages/common/src/editors/autocompleterEditor.ts index a5dd18f25..6c9023bea 100644 --- a/packages/common/src/editors/autocompleterEditor.ts +++ b/packages/common/src/editors/autocompleterEditor.ts @@ -196,7 +196,9 @@ export class AutocompleterEditor implements Ed destroy() { this._bindEventService.unbindAll(); - this._instance?.destroy(); + if (typeof this._instance?.destroy === 'function') { + this._instance.destroy(); + } this._inputElm?.remove?.(); this._elementCollection = null; } diff --git a/packages/common/src/editors/dateEditor.ts b/packages/common/src/editors/dateEditor.ts index fccdebdf5..d620f8e58 100644 --- a/packages/common/src/editors/dateEditor.ts +++ b/packages/common/src/editors/dateEditor.ts @@ -191,7 +191,7 @@ export class DateEditor implements Editor { this.hide(); this._bindEventService.unbindAll(); - if (this.flatInstance?.destroy) { + if (typeof this.flatInstance?.destroy === 'function') { this.flatInstance.destroy(); if (this.flatInstance?.element) { setTimeout(() => destroyObjectDomElementProps(this.flatInstance)); diff --git a/packages/common/src/editors/selectEditor.ts b/packages/common/src/editors/selectEditor.ts index 5cc85f506..732c758c6 100644 --- a/packages/common/src/editors/selectEditor.ts +++ b/packages/common/src/editors/selectEditor.ts @@ -421,7 +421,9 @@ export class SelectEditor implements Editor { } this._isDisposingOrCallingSave = true; - this._msInstance?.destroy(); + if (typeof this._msInstance?.destroy === 'function') { + this._msInstance.destroy(); + } this.editorElm?.remove(); this._msInstance = undefined; } diff --git a/packages/common/src/filters/autocompleterFilter.ts b/packages/common/src/filters/autocompleterFilter.ts index 78006bdd3..cf99191f2 100644 --- a/packages/common/src/filters/autocompleterFilter.ts +++ b/packages/common/src/filters/autocompleterFilter.ts @@ -237,7 +237,9 @@ export class AutocompleterFilter implements Fi * destroy the filter */ destroy() { - this._instance?.destroy(); + if (typeof this._instance?.destroy === 'function') { + this._instance.destroy(); + } if (this._filterElm) { // this._filterElm.autocomplete('destroy'); // this._filterElm.off('input').remove(); diff --git a/packages/common/src/filters/selectFilter.ts b/packages/common/src/filters/selectFilter.ts index 9c7401bb3..8398b2026 100644 --- a/packages/common/src/filters/selectFilter.ts +++ b/packages/common/src/filters/selectFilter.ts @@ -208,7 +208,9 @@ export class SelectFilter implements Filter { /** destroy the filter */ destroy() { - this._msInstance?.destroy(); + if (typeof this._msInstance?.destroy === 'function') { + this._msInstance.destroy(); + } this.filterElm?.remove(); // unsubscribe all the possible Observables if RxJS was used diff --git a/packages/common/src/services/filter.service.ts b/packages/common/src/services/filter.service.ts index ed8cdc4fa..a34c13d51 100644 --- a/packages/common/src/services/filter.service.ts +++ b/packages/common/src/services/filter.service.ts @@ -142,7 +142,9 @@ export class FilterService { if (Array.isArray(this._filtersMetadata)) { let filter = this._filtersMetadata.pop(); while (filter) { - filter?.destroy(); + if (typeof filter?.destroy === 'function') { + filter.destroy(); + } filter = this._filtersMetadata.pop(); } } diff --git a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts index 76de0cfed..8838b9574 100644 --- a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts +++ b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts @@ -438,7 +438,7 @@ export class SlickVanillaGridBundle { unsubscribeAll(this.subscriptions); this._eventPubSubService?.unsubscribeAll(); this.dataView?.setItems([]); - if (this.dataView?.destroy) { + if (typeof this.dataView?.destroy === 'function') { this.dataView?.destroy(); } this.slickGrid?.destroy(true); @@ -1478,7 +1478,9 @@ export class SlickVanillaGridBundle { // get current Editor, remove it from the DOm then re-enable it and re-render it with the new collection. const currentEditor = this.slickGrid.getCellEditor() as AutocompleterEditor | SelectEditor; if (currentEditor?.disable && currentEditor?.renderDomElement) { - currentEditor.destroy(); + if (typeof currentEditor.destroy === 'function') { + currentEditor.destroy(); + } currentEditor.disable(false); currentEditor.renderDomElement(newCollection); }