Created
May 17, 2013 13:10
-
-
Save raix/5598923 to your computer and use it in GitHub Desktop.
Debuggin template rendering in Meteor.
I had a template problem when creating a spreatsheet like app - optimizing usage of templates and dependenies is important when going mobile.
I created this snippet of code to repport in on Template rendering.
This file contains hidden or 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
var renderList = []; | |
var timer = 0; | |
var timeToLog = 100; | |
function debugRendered(templateName) { | |
// init renderList | |
renderList[templateName] = 0; | |
// Setup event | |
Template[templateName].rendered = function() { | |
renderList[templateName]++; | |
timer = 0; | |
}; | |
} | |
var templateNames = Object.keys(Template); | |
for (var i = 0; i < templateNames.length; i++ ) | |
debugRendered(templateNames[i]); | |
setInterval(function() { | |
timer++; | |
var header = true; | |
// Check if any changes since last time | |
if (timer > timeToLog) { | |
timer = 0; | |
for (var i = 0; i < templateNames.length; i++ ) { | |
var templateName = templateNames[i]; | |
if (renderList[templateName] > 0){ | |
if (header) | |
console.log('###### STATS TEMPLATE RENDERED ######'); | |
console.log(' rendered ' + renderList[templateName] + ' times - ' + templateName); | |
// Reset counter | |
renderList[templateName] = 0; | |
// Dont show header before next item | |
header = false; | |
} | |
} | |
} | |
}, 10); | |
console.log('###### Debug Template Rendering ######'); |
Thanks :)
Meteor Insights :) Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Very useful.