Imagine there is a Dashboard with some Items on the page. When page loads, e would like to handle it like this:
- Load and render the
Dashboard. - Use async call (
dojo.Deferred+setTimeout) to load allItems. - Add
Itemsto theDashboard.
Once an Item has been loaded, we add it to the Dashboard. During this async load we want the page to be available for interaction (UI-thread is not frozen).
The code should probably look like this:
var deferred = new Deffered();
setTimeout(function() {
array.forEach(items, function(item, i) {
loadItem();
deferred.progress(i + ' - loaded');
});
deferred.resolve();
}, 0)
deferred.then(function() {
addItemsToDashboard();
}, function(err) {
}, function(progress) {
console.debug('Update:', progress);
});
However this doesn't work as expected. The page got frozen for the whole duration of Items to load.
Any suggestion what is wrong or how to handle this?