Skip to content

Instantly share code, notes, and snippets.

@raix
Created May 17, 2013 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raix/5598923 to your computer and use it in GitHub Desktop.
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.
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 ######');
@DanielDornhardt
Copy link

Nice! Very useful.

@raix
Copy link
Author

raix commented Jun 6, 2013

Thanks :)

@marcoscuevas
Copy link

Meteor Insights :) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment