Added list template reflect option which will remove items from the source list if the items element is removed from the DOM. Added Title template helper. Cleaned up some code as well.

This commit is contained in:
2021-03-16 22:26:33 -07:00
parent 6986197339
commit 92a5eb3384
2 changed files with 111 additions and 16 deletions

View File

@ -55,6 +55,7 @@ class IgniteElement extends HTMLElement {
this.elements = [];
this.createProperties();
this.readyCallback = new IgniteCallback(() => this.ready());
this.onDisconnectCallbacks = [];
//Init the element before connected callback is fired
//Create a new rendering context so the init method can access properties correctly.
@ -249,11 +250,36 @@ class IgniteElement extends HTMLElement {
//Detach the after render callback
this.readyCallback.disconnect();
//Call any on disconnected callbacks
if (this.onDisconnectCallbacks) {
this.onDisconnectCallbacks.forEach(callback => callback.invoke(this));
}
//Cleanup this element if we need to.
this.cleanup();
}, 1);
}
/**
* Attaches a function to the on disconnect event for this element and returns a callback.
* @param {Function} onDisconnect Disconnect function to be called when on disconnect is raised.
* @returns IgniteCallback created for this callback.
*/
attachOnDisconnect(onDisconnect) {
var callback = new IgniteCallback(onDisconnect, detach => this.detachOnDisconnect(detach));
this.onDisconnectCallbacks.push(callback);
return callback;
}
/**
* Removes an ignite callback from the on disconnect event.
* @param {IgniteCallback} callback The ignite callback to disconnect.
* @ignore
*/
detachOnDisconnect(callback) {
this.onDisconnectCallbacks = this.onDisconnectCallbacks.filter(item => item != callback);
}
/**
* Returns the template to be rendered for this element.
*
@ -304,8 +330,8 @@ class IgniteElement extends HTMLElement {
* Generates a uuid and returns it.
*/
uuid() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
}