Don't ng-repeat function calls, they're expensive

See http://tech.small-improvements.com/2013/09/10/angularjs-performance-with-large-lists/
This commit is contained in:
Lorenz Hübschle-Schneider 2014-04-20 17:44:50 +02:00
parent e7d7f39c95
commit 3ad76d2ff3
2 changed files with 7 additions and 4 deletions

View file

@ -221,7 +221,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</div> </div>
<div bindonce id="bufferlines" class="monospace" ng-swipe-right="swipeSidebar()" ng-swipe-left="openNick()" ng-class="{'withnicklist': showNicklist, 'withsidebar': showSidebar}"> <div bindonce id="bufferlines" class="monospace" ng-swipe-right="swipeSidebar()" ng-swipe-left="openNick()" ng-class="{'withnicklist': showNicklist, 'withsidebar': showSidebar}">
<div id="nicklist" ng-show="showNicklist" ng-swipe-right="closeNick()" class="vertical-line-left"> <div id="nicklist" ng-show="showNicklist" ng-swipe-right="closeNick()" class="vertical-line-left">
<ul class="nicklistgroup list-unstyled" ng-repeat="group in activeBuffer().nicklist"> <ul class="nicklistgroup list-unstyled" ng-repeat="group in nicklist">
<li ng-repeat="nick in group.nicks|orderBy:'name'" ng-click="openBuffer(nick.name)"> <li ng-repeat="nick in group.nicks|orderBy:'name'" ng-click="openBuffer(nick.name)">
<a ng-click="nickAction(nick)"><span bo-class="nick.prefixClasses" bo-text="nick.prefix"></span><span bo-class="nick.nameClasses" bo-text="nick.name"></span></a> <a ng-click="nickAction(nick)"><span bo-class="nick.prefixClasses" bo-text="nick.prefix"></span><span bo-class="nick.nameClasses" bo-text="nick.name"></span></a>
</li> </li>
@ -236,7 +236,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tbody ng-repeat="bufferline in (bufferlines = activeBuffer().lines)"> <tbody ng-repeat="bufferline in bufferlines">
<tr class="bufferline"> <tr class="bufferline">
<td class="time"> <td class="time">
<span class="date" bo-class="{'repeated-time': bufferline.shortTime==bufferlines[$index-1].shortTime}"> <span class="date" bo-class="{'repeated-time': bufferline.shortTime==bufferlines[$index-1].shortTime}">

View file

@ -654,6 +654,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.$on('activeBufferChanged', function(event, unreadSum) { $rootScope.$on('activeBufferChanged', function(event, unreadSum) {
var ab = models.getActiveBuffer(); var ab = models.getActiveBuffer();
$scope.bufferlines = ab.lines;
$scope.nicklist = ab.nicklist;
if (ab.requestedLines < $scope.lines) { if (ab.requestedLines < $scope.lines) {
// buffer has not been loaded, but some lines may already be present if they arrived after we connected // buffer has not been loaded, but some lines may already be present if they arrived after we connected
@ -719,14 +721,15 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.buffers = models.model.buffers; $scope.buffers = models.model.buffers;
$scope.bufferlines = {};
$scope.nicklist = {};
$scope.activeBuffer = models.getActiveBuffer; $scope.activeBuffer = models.getActiveBuffer;
$rootScope.waseverconnected = false; $rootScope.waseverconnected = false;
$rootScope.models = models; $rootScope.models = models;
$rootScope.buffer = [];
$rootScope.iterCandidate = null; $rootScope.iterCandidate = null;
$store.bind($scope, "host", "localhost"); $store.bind($scope, "host", "localhost");