Added a rendering context which replaces the rendered flag on ignite elements so that properties won't return their value if we are rendering. This fixes an issue where lists would get messed up since they reconstruct whenever the list changes.

This commit is contained in:
2020-08-21 21:42:10 -07:00
parent 057960db8a
commit b0b9a83cc6
3 changed files with 77 additions and 11 deletions

View File

@ -1,3 +1,7 @@
/**
* The outline of a ignite property which is a managed property that
* can be used to invoke call back functions when the value of the property changes.
*/
class IgniteProperty {
constructor() {
this.callbacks = [];
@ -25,6 +29,18 @@ class IgniteProperty {
}
}
/**
* Return the value of the property if we try to convert
* the property to a string.
*/
IgniteProperty.prototype.toString = function () {
return this.value.toString();
}
/**
* The outline of a ignite property callback that allows
* disconnecting of callbacks on demand when they are no longer needed.
*/
class IgnitePropertyCallback {
constructor(property, callback) {
this.callback = callback;
@ -47,6 +63,38 @@ class IgnitePropertyCallback {
}
}
/**
* The outline of a simple rendering context which allows us to
* know if we are currently rendering anything ignite related. This works
* because Javascript is single threaded, if events could break the current execution
* this would fail. But it's safe since events cannot do that.
*/
class IgniteRenderingContext {
static enter() {
if (!IgniteRenderingContext.RenderCount) {
IgniteRenderingContext.RenderCount = 0;
}
IgniteRenderingContext.RenderCount++;
}
static leave() {
if (IgniteRenderingContext.RenderCount) {
IgniteRenderingContext.RenderCount--;
}
}
static get rendering() {
if (IgniteRenderingContext.RenderCount && IgniteRenderingContext.RenderCount > 0) {
return true;
}
return false;
}
}
window.IgniteRenderingContext = IgniteRenderingContext;
export {
IgniteProperty
};