Digest Cycles in Single Page Apps

Brendan Graetz

bguiz.com

@bguiz

What is a Digest Cycle?

What is a Digest Cycle?

Where are they used?

Where are they used?

Where are they -not- used?

Why are they important in SPAs?

(computed properties)

Computed properties allow you to treat a function like a property

App.Person = Ember.Object.extend({
    bmi: function() {
        var height = this.get('height');
        return this.get('weight') / height / height;
    }.property('weight', 'height')
});

Avoid in digest cycles

Too much work in each cycle

Misko Hevery on dirty checking tresholds

Avoid in digest cycles

Too much work in each cycle

var socket = io.connect();
return {
  on: function (eventName, callback) {
    socket.on(eventName, _.throttle(function () {
      var args = arguments;
      $rootScope.$apply(function () {
        callback.apply(socket, args);
      });
    }, 500));  // limit to once every 500ms
  }
  // ...
};

Credit: Huge Angular Apps - Brian Ford