Permalink
Browse files

add dom caching

  • Loading branch information...
1 parent 35746f9 commit c3974df006ddd189f1a21deccb39a58839cd310c @mape mape committed Aug 27, 2011
Showing with 20 additions and 11 deletions.
  1. +20 −11 public/javascripts/dashboard.js
@@ -1,12 +1,21 @@
(function() {
- var $templates = {};
- $('.template').each(function(index) {
- var $this = $(this);
- $templates[$this.attr('id')] = $($this.html());
- $this.remove();
- });
-
+ var $templates = {};
+ $('.template').each(function(index) {
+ var $this = $(this);
+ $templates[$this.attr('id')] = $($this.html());
+ $this.remove();
+ });
+ var domCache = {};
+ var $$ = (function() {
+ return function(selector) {
+ if (!domCache[selector]) {
+ domCache[selector] = $(selector);
+ }
+ return domCache[selector];
+ };
+ })();
$(document).bind('end.pjax', function(e, xhr, pjax) {
+ domCache = {};
if (ws) {
ws.disconnect();
}
@@ -40,7 +49,7 @@
$irc.find('.msg').text(irc.message);
$irc.find('.name').text(irc.from+':');
}
- $('.irc-dashboard ul').prepend($irc);
+ $$('.irc-dashboard ul').prepend($irc);
ircMessages.push($irc);
if (irc.length > 30) {
$.each(ircMessages.slice(0, ircMessages.length-30), function(index, $oldIrc) {
@@ -59,7 +68,7 @@
addDeploy(deploy);
});
ws.on('commits', function(commits) {
- var $gitubContainer = $('.github-commits ul').empty();
+ var $gitubContainer = $$('.github-commits ul').empty();
$.each(commits.teams, function(index, team) {
var $team = $templates.team.clone();
$team.find('.teamname').text(team.name).attr('href', '/teams/'+team.name).end()
@@ -95,7 +104,7 @@
.find('a.team').text(team.by).attr('href', "http://nodeknockout.com/teams/" + team.slug).end()
.find('.when').text('Deployed at: '+deploy.updatedAt.toString().match('..:..:..')[0]).end()
.find('.platform').text(deploy.platform).end()
- .prependTo($('.deploys-dashboard ul'));
+ .prependTo($$('.deploys-dashboard ul'));
deployList.push($deploy);
var maxCount = 30;
@@ -113,7 +122,7 @@
.find('.name').text(tweet.user.screen_name+':').attr('href', 'http://twitter.com/'+tweet.user.screen_name).end()
.find('.avatar').attr('src', tweet.user.profile_image_url);
- $('.twitter-dashboard ul.'+container).prepend($tweet);
+ $$('.twitter-dashboard ul.'+container).prepend($tweet);
var tweetsList = tweets[container];
tweetsList.push($tweet);

0 comments on commit c3974df

Please sign in to comment.