Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Last active August 29, 2015 14:02
Show Gist options
  • Save aaronfrost/eb2fb58e42490453140b to your computer and use it in GitHub Desktop.
Save aaronfrost/eb2fb58e42490453140b to your computer and use it in GitHub Desktop.
Talk about Debounces
<div ng-controller="TestCtrl" >
<div test-ctrl-move-handler="doMouseMoveEvent()" style="width:1000px;height:1000px;"></div>
</div>
angular.module('app').controller('TestCtrl', function($scope, element){
//Other Codes
//no more debounce in controller, cause it means that we are sad
})
.directive('testCtrlMoveHandler', function(){
//WAY LESS DIGESTS!!!!
return {
restrict: 'A',
link: function(scope, elem, attrs){
//This a jQuery handler. Won't cause $digest
elem.on('mousemove', function(){
if(something == true){
//this will cause $digests
scope.$eval(attrs.testCtrlMoveHandler);
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment