Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lib/router.js
- 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})
- };
- }
- });
- // lib/router.js
- var totalPostsCount = Posts.find().count()
- console.log('total count?')
- console.log(totalPostsCount) // output 0
- 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()};
- },
- subscriptions: function() {
- this.postsSub = Meteor.subscribe('posts', this.findOptions());
- },
- posts: function() {
- // console.log("is find limited to subscriptions too??");
- // console.log(Posts.find().count())
- return Posts.find({}, this.findOptions());
- },
- data: function() {
- // console.log('is data limited to this?')
- // console.log(Posts.find().count())
- var hasMore = this.posts().count() === this.postsLimit();
- var adjustOrNot = this.posts()
- if (!hasMore){
- var nextPath = this.route.path({postsLimit: this.posts().count()});
- }else{
- var nextPath = this.route.path({postsLimit: this.postsLimit() + this.increment});
- }
- return {
- posts: this.posts(),
- ready:this.postsSub.ready(),
- nextPath: hasMore ? nextPath : null
- };
- }
- });
- //...
- Router.route('/:postsLimit?', {
- name: 'postsList'
- });
Add Comment
Please, Sign In to add comment