mtr / angular-iscroll

AngularJS module that enables iScroll 5 functionality, wrapping it in an easy-to-use directive.
MIT License
74 stars 27 forks source link

Add option to skip digest cycle when refresh option is turned on #19

Closed dikaso closed 8 years ago

dikaso commented 8 years ago

Hey,

This is is a small optimization/option to skip dirty checking on refresh. If you have a lot of bindings refresh will cause huge performance loses.

Let me know if something is wrong.

mtr commented 8 years ago

Thanks, @DinkoMiletic. This seems like a nice little improvement. Do you have any example (and code) of how you would use this that I can include in the documentation too?

dikaso commented 8 years ago

Sure. Give me few days and I'll put it here.

mtr commented 8 years ago

Great. I'm looking forward to it.

dikaso commented 8 years ago

Passing invokeApply as false will skip angular model dirty checking on every run of asyncRefreshDelay or refreshInterval. This can result in huge performance gain if refreshInterval is set to really low value (e.g. 500ms).

iScrollServiceProvider.configureDefaults({
    iscroll: {
       invokeApply:false
   }
});

Let's test it. Past this code to your app run block:

/**
* this code is for measuring performances
* logs digest time in console
*/
var $oldDigest = $rootScope.$digest;
var $newDigest = function() {
        console.time("$digest");
       $oldDigest.apply($rootScope);
        console.timeEnd("$digest");
};
$rootScope.$digest = $newDigest;
  1. With invokeApply:true and refreshInterval:500 you'll see that digest is run every 500ms
  2. With invokeApply:false and refreshInterval:500 you'll see that digest is not invoked by angular-iScroll
mtr commented 8 years ago

Again, thank you for your contributions @DinkoMiletic. I've now finally incorporated your documentation too, and I've made invokeApply = false the new default.