Implemented a ready function that is only invoked once all ignite elements on a page are ready.

This commit is contained in:
2020-09-11 07:57:37 -07:00
parent 780f70188e
commit 0fcb908941
2 changed files with 52 additions and 1 deletions

View File

@ -205,6 +205,29 @@ class IgniteRenderingContext {
}
}
static ready(callback) {
//Setup the callbacks if it's not init'd.
if (!IgniteRenderingContext.ReadyCallbacks) {
IgniteRenderingContext.ReadyCallbacks = [];
}
//Add this ignite callback.
IgniteRenderingContext.ReadyCallbacks.push(callback);
//Clear the existing timer if there is one.
if (IgniteRenderingContext.ReadyTimer) {
clearTimeout(IgniteRenderingContext.ReadyTimer);
}
//Set a new timeout, it will only run once all elements are ready because
//of the way single threaded timers work.
IgniteRenderingContext.ReadyTimer = setTimeout(() => {
IgniteRenderingContext.ReadyCallbacks.forEach((ready) => ready.invoke());
IgniteRenderingContext.ReadyCallbacks = [];
IgniteRenderingContext.ReadyTimer = null;
}, 1);
}
static get rendering() {
if (IgniteRenderingContext.RenderCount && IgniteRenderingContext.RenderCount > 0) {
return true;