Improved ignite template deconstruct and construct functions. Simplified IgniteObject constructor.

This commit is contained in:
2023-04-24 13:39:50 -07:00
parent 018179ec56
commit 83e53ed4c3
2 changed files with 7 additions and 42 deletions

View File

@ -1155,7 +1155,9 @@ class IgniteTemplate {
}
//Invoke any refs we have and pass back the element reference.
this._refs.forEach((ref) => ref(this.element));
if (this._refs) {
this._refs.forEach((ref) => ref(this.element));
}
}
//Set the classes on this element
@ -1285,16 +1287,7 @@ class IgniteTemplate {
* there are no memory leaks.
*/
deconstruct() {
//Remove and disconnect all events
if (this.element && this._events) {
var keys = Object.keys(this._events);
for (var i = 0; i < keys.length; i++) {
this.element.removeEventListener(keys[i], this._events[keys[i]]);
}
this._events = null;
}
//Remove our element if we have one.
//Remove our element if we have one, this will destroy all events too.
if (this.element) {
this.element.remove();
this.element = null;
@ -1307,40 +1300,28 @@ class IgniteTemplate {
this.children[i].deconstruct();
}
}
this.children = null;
}
//Disconnect all callbacks
if (this._callbacks) {
this._callbacks.forEach((item) => item.disconnect());
this._callbacks = null;
}
//Stop observing resize events if we need to.
if (this._resizeObserver) {
this._resizeObserver.disconnect();
this._resizeObserver = null;
this._resizeObserverCallback = null;
}
//Stop observing intersects if we need to.
if (this._intersectObserver) {
this._intersectObserver.disconnect();
this._intersectObserver = null;
this._intersectObserverCallback = null;
}
//Remove any refs
//Invoke any refs and pass null.
if (this._refs) {
//Pass null to our refs so that the reference is updated.
this._refs.forEach(ref => ref(null));
this._refs = null;
}
//Invoke any custom destructors
if (this._destructors) {
this._destructors.forEach(d => d());
this._destructors = null;
}
}