-
-
Save nmccready/9d564782608d7c83aacf to your computer and use it in GitHub Desktop.
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
#shamelessly copied from | |
#http://tech.small-improvements.com/2013/09/10/angularjs-performance-with-large-lists/ | |
#https://gist.github.com/rkgarg/7232175 | |
app = require '../../app.coffee' | |
directiveName = 'postRepeat' | |
app.directive directiveName, [ '$log', | |
($log) -> | |
postRepeat = {} | |
scope: | |
options: '=' | |
link: (scope, element, attrs) -> | |
attrScope = scope.$parent | |
#root parent to all ng-repeats (encapsulating div or whatever) | |
parent = attrScope.$parent | |
if attrScope.$first | |
# lastTime can be updated anywhere if to reset counter at some | |
#action if ng-repeat is not getting started from $first | |
postRepeat[parent.$id] = | |
lastTime: new Date() | |
parent.$on '$destroy', -> | |
delete postRepeat[parent.$id] | |
if scope.options? | |
opts = scope.options | |
#use init function (via attribute binding (basically options)) to | |
# pass the postRepeat object on so the lastTime can be rest | |
opts.init(postRepeat[parent.$id],scope) if opts.init? and angular.isFunction opts.init | |
if attrScope.$last | |
scope.$evalAsync -> | |
$log.debug "## DOM rendering list took: " + | |
(new Date() - postRepeat[parent.$id].lastTime) + " ms" | |
doDelete = if not opts?.doDeleteLastTime? then true else opts?.doDeleteLastTime | |
delete postRepeat[parent.$id] if doDelete | |
] |
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
app.controller 'Ctrl', ($scope) -> | |
_postRepeat = null | |
$scope = | |
postRepeatOptions: | |
init: (postRepeat, scope) -> | |
_postRepeat = postRepeat | |
doDeleteLastTime: false | |
//some where down the line ... | |
//this is useful for testing infinite scroll where you need to not always erase lastTime untill specific momments | |
postRepeat.lastTime = new Date() |
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
<tr ng-repeat="item in items" post-repeat options="postRepeatOptions">…</tr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment