Skip to content

Instantly share code, notes, and snippets.

@dgs700
Created February 22, 2013 05:37
Show Gist options
  • Save dgs700/5010993 to your computer and use it in GitHub Desktop.
Save dgs700/5010993 to your computer and use it in GitHub Desktop.
Tibbr - Pattern for processing a large number of items without freezing the UI or causing long running script errors in IE
var arrayChunk = [],
//an array of models possibly with 100s or 1000s of items
//that need to be tranformed into views
combinedArray = users.models.concat( subjects.models).concat(broadcasts.models);
while( !_.isEmpty(combinedArray)){
//process 10 at a time
arrayChunk = combinedArray.splice(0, 10);
//wrapper around setTimeout 0 to defer execution to the end of the call stack
_.defer( function(chunk){
_.each(chunk, function(item){
$list.append( that.initChild( ListItem, {
model: item,
schedule: data
}).render().el);
});
}, arrayChunk);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment