Skip to content

Commit 672af33

Browse files
committed
worked on unmount to clean up nodes before removing
1 parent 0b10d62 commit 672af33

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modular-openscriptjs",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

src/component/Component.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import State from "../core/State.js";
55
import { container } from "../core/Container.js";
66
import {
77
cleanupDisconnectedComponents,
8+
destroyNodeDeep,
89
getOjsChildren,
910
} from "../utils/helpers.js";
11+
import DOM from "../utils/DOM.js";
1012

1113
/**
1214
* Base Component Class
@@ -145,7 +147,7 @@ export default class Component {
145147
getDeclaredListeners() {
146148
if (this.__ojsRegistered) {
147149
console.warn(
148-
`Component "component:${this.id}" is already registered. Skipping duplicate registration.`
150+
`Component "component:${this.id}" is already registered. Skipping duplicate registration.`,
149151
);
150152
return;
151153
}
@@ -200,12 +202,22 @@ export default class Component {
200202
* Deletes all the component's markup from the DOM
201203
*/
202204
unmount() {
205+
206+
/**
207+
* Clean up the dom based on the developer's logic.
208+
*/
209+
this.cleanUp();
210+
211+
/**
212+
* @var {NodeList<HTMLElement>} all
213+
*/
203214
let all = this.markup();
204215

205216
for (let elem of all) {
217+
destroyNodeDeep(elem);
206218
elem.remove();
207219
}
208-
220+
209221
this.releaseMemory();
210222
this.unmounted = true;
211223

@@ -249,7 +261,7 @@ export default class Component {
249261
if (!parent) parent = h.dom;
250262

251263
return parent.querySelectorAll(
252-
`ojs-${this.kebab(this.name)}[uid="${this.id}"]`
264+
`ojs-${this.kebab(this.name)}[uid="${this.id}"]`,
253265
);
254266
}
255267

@@ -272,7 +284,6 @@ export default class Component {
272284
releaseMemory() {
273285
container.resolve("repository").removeComponent(this.id);
274286
container.resolve("repository").removeComponentArgs(this.id);
275-
this.cleanUp();
276287

277288
this.emitter.clear();
278289

@@ -403,7 +414,7 @@ export default class Component {
403414
h.dom.querySelectorAll(
404415
`ojs-${this.kebab(this.name)}[uid="${
405416
this.id
406-
}"][s-${stateId}="${stateId}"]`
417+
}"][s-${stateId}="${stateId}"]`,
407418
) ?? [];
408419

409420
current.forEach((e) => {
@@ -491,7 +502,7 @@ export default class Component {
491502
const rendered = h[`ojs-${this.kebab(this.name)}`](
492503
attr,
493504
markup,
494-
cAttributes
505+
cAttributes,
495506
);
496507

497508
if (reconcileParent && parent) {

0 commit comments

Comments
 (0)