Skip to content

Commit 3b5c62c

Browse files
PB-166: Page Builder doesn't implement destroy method
1 parent 2a210db commit 3b5c62c

File tree

12 files changed

+119
-30
lines changed

12 files changed

+119
-30
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type-collection.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/master.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/preview.js

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/row/preview.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type-collection.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export default class ContentTypeCollection<P extends PreviewCollection = Preview
7171
this.collection.removeChild(child);
7272
}
7373

74+
/**
75+
* Destroys current instance and all children
76+
*/
77+
public destroy(): void {
78+
[...this.getChildren()()].forEach((elem: ContentTypeInterface) => {
79+
elem.destroy();
80+
});
81+
super.destroy();
82+
}
83+
7484
/**
7585
* Set the children observable array into the class
7686
*

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ export default class ContentType<P extends Preview = Preview, M extends Master =
4141
this.bindEvents();
4242
}
4343

44+
/**
45+
* Destroys current instance
46+
*/
47+
public destroy(): void {
48+
const params = {
49+
contentType: this,
50+
index: (this.parentContentType as ContentTypeCollectionInterface)
51+
.getChildren()
52+
.indexOf(this),
53+
parentContentType: this.parentContentType,
54+
stageId: this.stageId,
55+
};
56+
this.preview ? this.preview.destroy() : this.content.destroy();
57+
events.trigger("contentType:removeAfter", params);
58+
events.trigger(this.config.name + ":removeAfter", params);
59+
}
60+
4461
protected bindEvents() {
4562
const eventName: string = this.config.name + ":" + this.id + ":updateAfter";
4663
const paramObj: any = {};

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ export default interface ContentTypeInterface<P extends Preview = Preview, M ext
1919
preview: P;
2020
content: M;
2121
dropped: boolean;
22+
23+
/**
24+
* Destroys current instance
25+
*/
26+
destroy(): void;
2227
}

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/master.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export default class Master {
6868
return result;
6969
}
7070

71+
/**
72+
* Destroys current instance
73+
*/
74+
public destroy(): void {
75+
return;
76+
}
77+
7178
/**
7279
* Attach event to updating data in data store to update observables
7380
*/

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,26 +331,13 @@ export default class Preview implements PreviewInterface {
331331
*/
332332
public onOptionRemove(): void {
333333
const removeContentType = () => {
334-
const dispatchRemoveEvent = () => {
335-
const params = {
336-
contentType: this.contentType,
337-
index: (this.contentType.parentContentType as ContentTypeCollectionInterface)
338-
.getChildren()
339-
.indexOf(this.contentType),
340-
parentContentType: this.contentType.parentContentType,
341-
stageId: this.contentType.stageId,
342-
};
343-
events.trigger("contentType:removeAfter", params);
344-
events.trigger(this.contentType.config.name + ":removeAfter", params);
345-
};
346-
347334
if (this.wrapperElement) {
348335
// Fade out the content type
349336
$(this.wrapperElement).fadeOut(350 / 2, () => {
350-
dispatchRemoveEvent();
337+
this.contentType.destroy();
351338
});
352339
} else {
353-
dispatchRemoveEvent();
340+
this.contentType.destroy();
354341
}
355342
};
356343

@@ -391,6 +378,13 @@ export default class Preview implements PreviewInterface {
391378
return getSortableOptions(this);
392379
}
393380

381+
/**
382+
* Destroys current instance
383+
*/
384+
public destroy(): void {
385+
return;
386+
}
387+
394388
/**
395389
* Get the CSS classes for the children element, as we dynamically create this class name it can't sit in the DOM
396390
* without causing browser issues

0 commit comments

Comments
 (0)