Last active
August 29, 2015 14:02
-
-
Save aaronfrost/eb2fb58e42490453140b to your computer and use it in GitHub Desktop.
Talk about Debounces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="TestCtrl" > | |
<div test-ctrl-move-handler="doMouseMoveEvent()" style="width:1000px;height:1000px;"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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