Added deconstruct functionality and cleanup code so that everything gets correctly cleaned up once a element is removed from the DOM. Added a new property template that allows properties to be used as content or html anywhere within a template's children. Next up is slot support.

This commit is contained in:
2020-07-28 22:23:49 -07:00
parent 1adb844c97
commit 43962757f0
5 changed files with 255 additions and 54 deletions

View File

@ -1,6 +1,6 @@
class IgniteProperty {
constructor() {
this.onPropertyChange = [];
this.callbacks = [];
this._value = null;
}
@ -12,17 +12,41 @@ class IgniteProperty {
var old = this._value;
this._value = val;
for (var i = 0; i < this.onPropertyChange.length; i++) {
this.onPropertyChange[i](old, val);
//Invoke any callbacks letting them know the value changed.
for (var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i].invoke(old, val);
}
}
attach(onChange) {
var callback = new IgnitePropertyCallback(this, onChange);
this.callbacks.push(callback);
return callback;
}
}
class IgnitePropertyCallback {
constructor(property, callback) {
this.callback = callback;
this.property = property;
}
invoke(oldValue, newValue) {
if (this.callback) {
this.callback(oldValue, newValue);
}
}
disconnect() {
this.callback = null;
if (this.property) {
this.property.callbacks = this.property.callbacks.filter(callback => callback != this);
this.property = null;
}
}
}
class IgniteAttribute {
}
export {
IgniteProperty,
IgniteAttribute
IgniteProperty
};