Skip to content

Commit 9b9830d

Browse files
committed
Set CommentsPerLineView.line in the constructor
Before it was set when the first comment was added, but we know the line at creation, so it’s cleaner to set it then.
1 parent 2b317de commit 9b9830d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

code_comments/htdocs/code-comments.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
addOne: function(comment) {
113113
var line = comment.get('line');
114114
if (!this.viewPerLine[line]) {
115-
this.viewPerLine[line] = new CommentsForALineView();
115+
this.viewPerLine[line] = new CommentsForALineView( { line: line } );
116116

117117
var $tr = $( CodeComments.$tableRows[ line-1 ] );
118118

@@ -134,6 +134,7 @@
134134
template: _.template(CodeComments.templates.comments_for_a_line),
135135
templateData: {},
136136
initialize: function(attrs) {
137+
this.line = attrs.line;
137138
this.templateData.colspan = ( 'changeset' === CodeComments.page ) ? 2 : 1;
138139
},
139140
events: {
@@ -145,8 +146,10 @@
145146
return this;
146147
},
147148
addOne: function(comment) {
149+
if ( comment.get( 'line' ) != this.line ) {
150+
throw 'Trying to add a comment with line ' + comment.get( 'line' ) + ' into a view for line ' + this.line;
151+
}
148152
var view = new CommentView({model: comment});
149-
this.line = comment.get('line');
150153
view.appendTo( $( "ul.comments" ) );
151154
},
152155
showAddCommentDialog: function() {

0 commit comments

Comments
 (0)