javascript - while vs setInterval -



javascript - while vs setInterval -

i have next array monitor widgets initiated app i'm working on:

widgets = [{ selector: ".table", init: function() {...} }, { selector: ".anothertable", init: function() {...} }]

each init function invoking plugin. when plugin has finished tasks pushes selector (e.g ".table") array called "readywidgets"

now question this:

how can tell 1 time selectors nested under primary widgets array nowadays in readywidgets array?

i'm kind of having blackout, although have solution, think there improve 1 i'm missing.

this came with:

init: function() { // hold each widget selector // , later in readywidgets array var widgetspending = [] // initialize each widget in widgets array // (only if selector matches @ to the lowest degree 1 element) this.widgets.foreach(function(widget) { $(widget.selector).length && widgetspending.push(widget.selector) && widget.init() }, this) // utilize setinterval check if values in widgetspending array // nowadays within this.readywidgets var = var interval = setinterval(function() { // temporary create sure interval cleared console.log(that.readywidgets) // if value in widgetspending not found in // that.readywidgets, pageready marked false var pageready = true widgetspending.foreach(function(selector) { if (that.readywidgets.indexof(selector) == -1) { pageready = false } }) // if widgetsready true, clear interval pageready && clearinterval(interval) }, 300) }

if have suggestions on how improve this, tell :)

something this:

var loadoperations = []; objects.foreach(function (obj) { var loadcomplete = $.deferred(); loadoperations.push(loadcomplete); // long running async function call. function can homecoming deferred or promise obj.somelongrunningegloadoperation(function() { // async function finish callback loadcomplete.resolve(); }); }); $.when.apply($, loadoperations).done(function () { // long running operations completed });

javascript jquery loops

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -