Skip to content

Commit 29bb1a7

Browse files
committed
Add fetchComments function to abstract parameters to fetch()
Views shouldn't have to care about fetch() parameters, so this abstracts the fetch() call into the model. The CommentsList model now provides a fetchComments() function. Its optional argument, commentsToFetch, defaults to top-level comments but can be set to 'line' to request inline comments instead.
1 parent 554b7b1 commit 29bb1a7

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

code_comments/htdocs/code-comments.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525
url: CodeComments.comments_rest_url,
2626
comparator: function(comment) {
2727
return comment.get('time');
28+
},
29+
fetchComments: function( commentsToFetch ) {
30+
var lineQuery = ( 'line' == commentsToFetch ) ? 'line__gt' : 'line',
31+
params = {
32+
data: {
33+
path: CodeComments.path || undefined,
34+
revision: CodeComments.revision,
35+
type: CodeComments.type,
36+
}
37+
};
38+
params.data[lineQuery] = 0;
39+
40+
return this.fetch( params );
2841
}
2942
});
3043

@@ -60,15 +73,7 @@
6073
render: function() {
6174
$(this.el).html(this.template());
6275
this.$('button').button();
63-
var params = {
64-
data: {
65-
path: CodeComments.path,
66-
revision: CodeComments.revision,
67-
line: 0,
68-
type: CodeComments.type,
69-
}
70-
};
71-
TopComments.fetch( params );
76+
TopComments.fetchComments();
7277
return this;
7378
},
7479

@@ -96,16 +101,7 @@
96101
this.viewPerLine = {};
97102
},
98103
render: function() {
99-
var params = {
100-
data: {
101-
path: CodeComments.path || undefined,
102-
revision: CodeComments.revision,
103-
line__gt: 0,
104-
type: CodeComments.type,
105-
}
106-
};
107-
108-
LineComments.fetch( params ).complete( function() {
104+
LineComments.fetchComments( 'line' ).complete( function() {
109105
window.setTimeout( function() {
110106
var anchor_id = '#comment-' + CodeComments.active_comment_id;
111107
if ( '' != anchor_id && $( anchor_id ).offset() ) {

0 commit comments

Comments
 (0)