Skip to content

A rewrite of the Ember.js run loop as a generic microlibrary

Notifications You must be signed in to change notification settings

rwjblue/backburner.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

backburner.js Build Status

A rewrite of the Ember.js run loop as a generic microlibrary.

API

Constructor

new Backburner() - instantiate a Backburner instance with an array of queue names

Instance methods

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#throttle - rate-limit the passed function for a specified amount of time

Backburner#cancel - cancel a deferOnce or setTimeout

Example usage

The following code will only cause a single DOM manipulation:

var backburner = new Backburner(['render']),
    person = {name: "Erik"};

function updateName() {
  $('#name').text(person.name);
}

function setName(name) {
  person.name = name;
  backburner.deferOnce('render', updateName);
}

backburner.run(function() {
  setName("Kris");
  setName("Tom");
  setName("Yehuda");
});

Simple Backbone Example

app.TodoView = Backbone.View.extend({
  // ...

  initialize: function () {
    this.listenTo(this.model, 'change', this.render);
  },

  render: function() {
    // put the rerender on the backburner!
    backburner.deferOnce('render', this, this.actuallyRender);
  },

  actuallyRender: function() {
    // do our DOM manipulations here. will only be called once.
  }

  // ...
});


// ... somewhere in our app code ...
backburner.run(function() {
  model.set('firstName', 'Erik');
  model.set('lastName',  'Bryn');
});

// our view has been rerendered only once, thanks to backburner!

Bitdeli Badge

About

A rewrite of the Ember.js run loop as a generic microlibrary

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.0%
  • CSS 3.0%