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

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

View File

@ -413,6 +413,7 @@ class IgniteProperty {
/**
* Return the value of the property if we try to convert
* the property to a string.
* @ignore
*/
IgniteProperty.prototype.toString = function () {
if (this.value) {
@ -462,24 +463,7 @@ Array.prototype.getOldPropertyValues = function (property, oldValue) {
* The outline of an IgniteObject which contains IgniteProperties.
*/
class IgniteObject {
/**
* Creates a new IgniteObject from an object and returns it.
* @param {Any} obj The object to create an IgniteObject out of.
* @returns {IgniteObject} The ignite object created.
*/
constructor(obj) {
//Only do this if the object is not an ignite object already.
if (!(obj instanceof IgniteObject)) {
Object.keys(obj).forEach(name => {
var prop = new IgniteProperty(obj[name]);
Object.defineProperty(this, name, {
get: () => { return (IgniteRendering.rendering ? prop : prop.value); },
set: (value) => { prop.value = value; }
});
});
} else {
return obj;
}
constructor() {
}
/**

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;
}
}