From: Jack Allnutt Date: Mon, 20 May 2013 19:17:07 +0000 (+0100) Subject: Avoid re-creating the member list elements on every change X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=aa4f5ba5fbf0d0f2b5ade3cd771270061e3ab4ba;p=KiwiIRC.git Avoid re-creating the member list elements on every change --- diff --git a/client/assets/dev/model_member.js b/client/assets/dev/model_member.js index 22fb2d6..bc2fa60 100644 --- a/client/assets/dev/model_member.js +++ b/client/assets/dev/model_member.js @@ -32,6 +32,7 @@ _kiwi.model.Member = Backbone.Model.extend({ this.sortModes(modes); this.set({"nick": nick, "modes": modes, "prefix": this.getPrefix(modes)}, {silent: true}); this.isOp(); + this.view = new _kiwi.view.Member({"model": this}); }, addMode: function (mode) { var modes_to_add = mode.split(''), diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index 1a763af..11b2f9f 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -1,5 +1,21 @@ /*jslint white:true, regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */ /*global kiwi */ +_kiwi.view.Member = Backbone.View.extend({ + tagName: "li", + initialize: function (options) { + this.model.bind('change', this.render, this); + this.render(); + }, + render: function () { + var $this = this.$el, + prefix_css_class = (this.model.get('modes') || []).join(' '); + + $this.addClass('mode ' + prefix_css_class); + $this.html('' + this.model.get("prefix") + '' + this.model.get("nick") + ''); + $this.data('member', this.model); + return this; + } +}); _kiwi.view.MemberList = Backbone.View.extend({ tagName: "ul", @@ -11,20 +27,18 @@ _kiwi.view.MemberList = Backbone.View.extend({ $(this.el).appendTo('#kiwi .memberlists'); }, render: function () { - var $this = $(this.el); + var $this = this.$el; $this.empty(); this.model.forEach(function (member) { - var prefix_css_class = (member.get('modes') || []).join(' '); - $('
  • ' + member.get("prefix") + '' + member.get("nick") + '
  • ') - .appendTo($this) - .data('member', member); + $this.append(member.view.el); }); + return this; }, nickClick: function (event) { var $target = $(event.currentTarget).parent('li'), member = $target.data('member'), userbox; - + event.stopPropagation(); // If the userbox already exists here, hide it