Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 1d4f4a9

Browse files
committed
start breaking out the fetch
1 parent 18ce760 commit 1d4f4a9

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

js/collections/usersShortCl.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
var Backbone = require('backbone'),
2+
app = require('../App.js').getApp(),
23
userShort = require('../models/userShortMd');
34

45
module.exports = Backbone.Collection.extend({
5-
model: userShort
6+
model: userShort,
7+
8+
initialize: function(models, options){
9+
this.fetchURL = options.fetchURL;
10+
},
11+
12+
url: function() {
13+
return app.serverConfigs.getActive().getServerBaseUrl() + '/' + this.fetchURL;
14+
}
615
});

js/views/userListVw.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ module.exports = Backbone.View.extend({
1717
options.serverUrl: server url to pass into each user view
1818
options.ownFollowing: array of guids this user is following
1919
options.hideFollow: boolean, hide follow button
20-
options.reverse; should the list of users be reversed?
20+
options.reverse: should the list of users be reversed?
21+
options.perFetch: the number of users returned per fetch (optional, only applies to the get_followers api)
2122
*/
2223
//the model must be passed in by the constructor
2324
this.usersShort = new usersShortCollection(this.model);
2425
this.options.reverse && this.usersShort.models.reverse();
2526
this.subViews = [];
2627
this.showPerScroll = 10;
28+
this.fetchMoreAfter = options.perFetch;
2729
this.nextUserToShow = 0;
2830
this.totalUsers = this.usersShort.length;
2931
this.$container = $('#obContainer');
@@ -71,6 +73,9 @@ module.exports = Backbone.View.extend({
7173
}
7274

7375
this.nextUserToShow = this.nextUserToShow >= this.totalUsers ? this.nextUserToShow : this.nextUserToShow + this.showPerScroll;
76+
if(this.fetchMoreAfter && this.totalUsers == this.fetchMoreAfter){
77+
this.trigger('fetch')
78+
}
7479
},
7580

7681
renderUser: function(item){

js/views/userPageVw.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ module.exports = baseVw.extend({
183183
//set view's userID from the userModel;
184184
this.userID = options.userModel.get('guid');
185185
this.userProfileFetchParameters = {};
186+
this.followerFetchStart = 0;
186187
this.itemFetchParameters = {};
187188
this.model = new Backbone.Model();
188189
this.globalUserProfile = options.userProfile;
@@ -280,7 +281,6 @@ module.exports = baseVw.extend({
280281
} else {
281282
this.options.ownPage = false;
282283
this.userProfileFetchParameters = $.param({'guid': this.pageID});
283-
//this.userProfileFetchParameters = $.param({'guid': this.pageID, 'start': 0});
284284
}
285285

286286
this.userProfileFetch = this.userProfile.fetch({
@@ -687,20 +687,29 @@ module.exports = baseVw.extend({
687687
},
688688

689689
fetchFollowers: function(){
690-
var self = this;
690+
var self = this,
691+
fetchFollowersParameters;
692+
693+
if(this.ownPage){
694+
fetchFollowersParameters = $.param({'start': this.followerFetchStart});
695+
} else {
696+
fetchFollowersParameters = $.param({'guid': this.pageID, 'start': this.followerFetchStart});
697+
}
691698

692699
this.followers.fetch({
693700
data: self.userProfileFetchParameters,
694701
//timeout: 5000,
695-
success: function(model){
702+
success: (model)=> {
696703
var followerArray = model.get('followers');
704+
this.$('.js-userFollowerCount').html(model.get('count'));
705+
this.followerFetchStart += model.length;
697706

698707
if (self.isRemoved()) return;
699708

700-
self.renderFollowers(followerArray);
709+
this.renderFollowers(followerArray);
701710
//if this is not their page, see if they are being followed
702-
if(self.options.ownPage === false){
703-
self.toggleFollowButtons(Boolean(__.findWhere(followerArray, {guid: self.userID})));
711+
if(this.options.ownPage === false){
712+
this.toggleFollowButtons(Boolean(__.findWhere(followerArray, {guid: this.userID})));
704713
}
705714
},
706715
error: function(model, response){
@@ -796,12 +805,11 @@ module.exports = baseVw.extend({
796805
ownFollowing: this.ownFollowing,
797806
hideFollow: true,
798807
serverUrl: this.options.userModel.get('serverUrl'),
799-
reverse: true
808+
reverse: true,
809+
perFetch: 30
800810
});
801811
this.registerChild(this.followerList);
802812

803-
this.$('.js-userFollowerCount').html(model.length);
804-
805813
if (model.length) {
806814
this.followersSearch = new window.List('searchFollowers', {
807815
valueNames: ['js-searchName', 'js-searchHandle'],

0 commit comments

Comments
 (0)