Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Backbone Sleepable View
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Backbone.SleepableView.js
README.md

README.md

Backbone.SleepableView

A simplistic Backbone View extension enabling the toggling of render as an op (awake) or no-op (sleeping) routine.

           __..--''``\--....___   _..,_
       _.-'    .-/";  `        ``<._  ``-+'~=.
   _.-' _..--.'_    \                    `(^) )
  ((..-'    (< _     ;_..__               ; `'   fL
             `-._,_)'      ``--...____..-'

Sleepable View

var View = Backbone.SleepableView.extend({
    initialize: function() {
        Backbone.SleepableView.prototype.initialize.apply(this, arguments);
        this.model.on('change:n', this.render, this);
    },
    fib: function(n){
        if (n<=1) {
            return n;
        } else {
            return fib(n-1) + fib(n-2);
        }
    },
    render: function() {
        this.$el.html(this.fib(this.model.get('n')));
    }

});

var model = new Backbone.Model,
    view = new View({model: model});
view.sleep();
for (var i=0; i<100000; i++) {
    model.set('n', i); //phew, no ember heat!
}
model.set('n', 10);
view.wake();
console.log(view.$el.html());
Something went wrong with that request. Please try again.