Skip to content

Instantly share code, notes, and snippets.

@rhutchison
Last active September 1, 2015 03:20
Show Gist options
  • Save rhutchison/98bda7b51e9045e1cd08 to your computer and use it in GitHub Desktop.
Save rhutchison/98bda7b51e9045e1cd08 to your computer and use it in GitHub Desktop.

Revisions

  1. rhutchison revised this gist Sep 1, 2015. 1 changed file with 12 additions and 6 deletions.
    18 changes: 12 additions & 6 deletions post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,12 @@
    angular.module('myApp').directive('postRepeatDirective',
    ['$timeout',
    function($timeout) {
    return function(scope) {
    return function(scope, element, attrs) {
    var timerName = attrs.postRepeatDirective || 'postRepeatDirective';

    if (scope.$first) {
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    console.time(timerName);
    } else {
    window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    }
    @@ -14,10 +16,10 @@ angular.module('myApp').directive('postRepeatDirective',
    if (scope.$last) {
    $timeout(function() {
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    console.timeEnd('postRepeatDirective');
    console.time(timerName);
    console.timeEnd(timerName);
    } else if (window.console) {
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    console.log("## DOM(" + timerName + ") rendering list took: " + (new Date() - window.a) + " ms");
    }
    });
    }
    @@ -26,4 +28,8 @@ angular.module('myApp').directive('postRepeatDirective',
    ]);

    // Use in HTML:
    <tr ng-repeat="item in items" post-repeat-directive></tr>
    <tr ng-repeat="item in items" post-repeat-directive></tr>

    OR

    <tr ng-repeat="item in items" post-repeat-directive="itemList"></tr>
  2. rhutchison revised this gist Sep 1, 2015. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,7 @@ angular.module('myApp').directive('postRepeatDirective',
    if (scope.$first) {
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    }
    else {
    } else {
    window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    }
    }
    @@ -17,11 +16,8 @@ angular.module('myApp').directive('postRepeatDirective',
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    console.timeEnd('postRepeatDirective');
    }
    else {
    if (window.console) {
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    }
    } else if (window.console) {
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    }
    });
    }
  3. @riddla riddla revised this gist Dec 17, 2013. 1 changed file with 28 additions and 12 deletions.
    40 changes: 28 additions & 12 deletions post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,33 @@
    // Post repeat directive for logging the rendering time
    angular.module('myApp').directive('postRepeatDirective',
    ['$timeout',
    function($timeout) {
    return function(scope) {
    if (scope.$first)
    window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    if (scope.$last)
    $timeout(function(){
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    });
    };
    }
    ]);
    ['$timeout',
    function($timeout) {
    return function(scope) {
    if (scope.$first) {
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    }
    else {
    window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    }
    }

    if (scope.$last) {
    $timeout(function() {
    if (window.console && window.console.time) {
    console.time('postRepeatDirective');
    console.timeEnd('postRepeatDirective');
    }
    else {
    if (window.console) {
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    }
    }
    });
    }
    };
    }
    ]);

    // Use in HTML:
    <tr ng-repeat="item in items" post-repeat-directive></tr>
  4. @rkgarg rkgarg revised this gist Oct 31, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,7 @@ angular.module('myApp').directive('postRepeatDirective',
    });
    };
    }
    ]);
    ]);

    // Use in HTML:
    <tr ng-repeat="item in items" post-repeat-directive></tr>
  5. @rkgarg rkgarg revised this gist Oct 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ angular.module('myApp').directive('postRepeatDirective',
    function($timeout) {
    return function(scope) {
    if (scope.$first)
    window.a = new Date(); # window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    window.a = new Date(); // window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    if (scope.$last)
    $timeout(function(){
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
  6. @rkgarg rkgarg revised this gist Oct 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ angular.module('myApp').directive('postRepeatDirective',
    function($timeout) {
    return function(scope) {
    if (scope.$first)
    window.a = new Date();
    window.a = new Date(); # window.a can be updated anywhere if to reset counter at some action if ng-repeat is not getting started from $first
    if (scope.$last)
    $timeout(function(){
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
  7. @rkgarg rkgarg created this gist Oct 30, 2013.
    14 changes: 14 additions & 0 deletions post-repeat-directive.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // Post repeat directive for logging the rendering time
    angular.module('myApp').directive('postRepeatDirective',
    ['$timeout',
    function($timeout) {
    return function(scope) {
    if (scope.$first)
    window.a = new Date();
    if (scope.$last)
    $timeout(function(){
    console.log("## DOM rendering list took: " + (new Date() - window.a) + " ms");
    });
    };
    }
    ]);