Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#shamelessly copied from
app = require '../../'
directiveName = 'postRepeat'
app.directive directiveName, [ '$log',
($log) ->
postRepeat = {}
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
app.controller 'Ctrl', ($scope) ->
_postRepeat = null
$scope =
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()
<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
You can’t perform that action at this time.