A rewrite of the Ember.js run loop as a generic microlibrary.
More details soon... until then, look at the source and the tests.
new Backburner()
- instantiate a Backburner instance with an array of queue names
Backburner#run
- execute the passed function and flush any deferred actions
Backburner#defer
- defer the passed function to run inside the specified queue
Backburner#deferOnce
- defer the passed function to run inside the specified queue, only execute it once
Backburner#setTimeout
- execute the passed function in a specified amount of time
Backburner#debounce
- execute the passed function in a specified amount of time, reset timer upon additional calls
Backburner#cancel
- cancel a deferOnce
or setTimeout
The following code will only cause a single DOM manipulation:
var backburner = new Backburner(['render']),
person = {name: "Erik"};
function updateName() {
backburner.deferOnce('render', function() {
$('#name').text(person.name);
});
}
function setName(name) {
person.name = name;
updateName();
}
backburner.run(function() {
setName("Kris");
setName("Tom");
setName("Yehuda");
});