Skip to content

Commit

Permalink
Improve Angular digest performance by allowing watching table definit…
Browse files Browse the repository at this point in the history
…ions shallowly
  • Loading branch information
Robinson7D committed Dec 10, 2014
1 parent afe18b5 commit 2cfd582
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
14 changes: 12 additions & 2 deletions dist/angular-datatables.js
Expand Up @@ -375,7 +375,7 @@
compile: function (tElm) {
var _staticHTML = tElm[0].innerHTML;
return function postLink($scope, $elem, iAttrs, ctrl) {
$scope.$watch('[dtOptions, dtColumns, dtColumnDefs]', function (newVal, oldVal) {
function handleChanges(newVal, oldVal) {
if (newVal !== oldVal) {
var newDTOptions = newVal[0], oldDTOptions = oldVal[0];
// Do not rerender if we want to reload. There are already
Expand All @@ -388,7 +388,17 @@
newDTOptions.reload = false;
}
}
}, true);
}
// Options can hold heavy data, and other deep/large objects.
// watchcollection can improve this by only watching shallowly
var watchFunction = iAttrs.disableDeepWatchers ? '$watchCollection' : '$watch';
angular.forEach([
'dtColumns',
'dtColumnDefs',
'dtOptions'
], function (tableDefField) {
$scope[watchFunction].call($scope, tableDefField, handleChanges, true);
});
ctrl.showLoading($elem);
ctrl.render($elem, ctrl.buildOptionsPromise(), _staticHTML);
};
Expand Down

0 comments on commit 2cfd582

Please sign in to comment.