Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): make sure destroy is a function before calling it #1148

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/common/src/editors/autocompleterEditor.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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