Skip to content

Instantly share code, notes, and snippets.

@lega911
Created March 13, 2014 07:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lega911/9523350 to your computer and use it in GitHub Desktop.
Save lega911/9523350 to your computer and use it in GitHub Desktop.
timeit = function(fn) {
var a = (new Date()).valueOf();
fn();
console.log((new Date()).valueOf() - a);
}
this.renderWithJS = function() {
timeit(function() {
var d = ['<ul class="list-group">'];
var i, user;
for(i=0;i<$scope.users.length;i++) {
user = $scope.users[i];
d.push('<li class="list-group-item">' + user.id + ': ' + user.firstName + ' - ' + user.lastName + '</li>')
}
d.push('</ul>')
element.innerHTML = d.join('');
})
}
this.renderWithJS2 = function() {
timeit(function() {
var ul = document.createElement('ul');
ul.className = 'list-group';
var i, user, li;
for(i=0;i<$scope.users.length;i++) {
user = $scope.users[i];
li = document.createElement('li')
li.className = 'list-group-item'
li.addEventListener('click', (function(user){
return function(){
$scope.userSelected(user)
}
})(user))
li.innerText = user.id + ': ' + user.firstName + ' - ' + user.lastName;
ul.appendChild(li);
}
element.appendChild(ul);
})
}
this.renderWithReact = function() {
timeit(function() {
React.renderComponent(UserList({scope: $scope}), element);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment