Skip to content

Commit

Permalink
Refactored postsLists route into a RouteController
Browse files Browse the repository at this point in the history
chapter12-3
  • Loading branch information
tmeasday committed Oct 19, 2015
1 parent c298060 commit 223c5e9
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ Router.configure({
}
});

PostsListController = RouteController.extend({
template: 'postsList',
increment: 5,
postsLimit: function() {
return parseInt(this.params.postsLimit) || this.increment;
},
findOptions: function() {
return {sort: {submitted: -1}, limit: this.postsLimit()};
},
waitOn: function() {
return Meteor.subscribe('posts', this.findOptions());
},
data: function() {
return {posts: Posts.find({}, this.findOptions())};
}
});


Router.route('/posts/:_id', {
name: 'postPage',
waitOn: function() {
Expand All @@ -23,17 +41,7 @@ Router.route('/posts/:_id/edit', {
Router.route('/submit', {name: 'postSubmit'});

Router.route('/:postsLimit?', {
name: 'postsList',
waitOn: function() {
var limit = parseInt(this.params.postsLimit) || 5;
return Meteor.subscribe('posts', {sort: {submitted: -1}, limit: limit});
},
data: function() {
var limit = parseInt(this.params.postsLimit) || 5;
return {
posts: Posts.find({}, {sort: {submitted: -1}, limit: limit})
};
}
name: 'postsList'
});

var requireLogin = function() {
Expand Down

0 comments on commit 223c5e9

Please sign in to comment.