Created
February 22, 2013 05:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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