Skip to content

Commit

Permalink
fix(common): make sure destroy is a function before calling it (#1148)
Browse files Browse the repository at this point in the history
* 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 <Ghislain.Beaulac@se.com>
  • Loading branch information
ghiscoding and ghiscoding-SE committed Oct 24, 2023
1 parent 1fd2739 commit dba9606
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/common/src/editors/autocompleterEditor.ts
Expand Up @@ -196,7 +196,9 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed

destroy() {
this._bindEventService.unbindAll();
this._instance?.destroy();
if (typeof this._instance?.destroy === 'function') {
this._instance.destroy();
}
this._inputElm?.remove?.();
this._elementCollection = null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/dateEditor.ts
Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/editors/selectEditor.ts
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/filters/autocompleterFilter.ts
Expand Up @@ -237,7 +237,9 @@ export class AutocompleterFilter<T extends AutocompleteItem = any> 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();
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/filters/selectFilter.ts
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/services/filter.service.ts
Expand Up @@ -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();
}
}
Expand Down
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit dba9606

Please sign in to comment.