Guest User

Untitled

a guest
Aug 24th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. // lib/router.js
  2. Router.route('/:postsLimit?', {
  3. name: 'postsList',
  4. waitOn: function() {
  5. var limit = parseInt(this.params.postsLimit) || 5;
  6. return Meteor.subscribe('posts', {sort: {submitted: -1}, limit: limit});
  7. },
  8. data: function() {
  9. var limit = parseInt(this.params.postsLimit) || 5;
  10. return {
  11. posts: Posts.find({}, {sort: {submitted: -1}, limit: limit})
  12. };
  13. }
  14. });
  15.  
  16. // lib/router.js
  17. var totalPostsCount = Posts.find().count()
  18. console.log('total count?')
  19. console.log(totalPostsCount) // output 0
  20.  
  21.  
  22. PostsListController = RouteController.extend({
  23. template: 'postsList',
  24. increment: 5,
  25. postsLimit: function() {
  26. return parseInt(this.params.postsLimit) || this.increment;
  27. },
  28. findOptions: function() {
  29. return {sort: {submitted: -1}, limit: this.postsLimit()};
  30. },
  31. subscriptions: function() {
  32. this.postsSub = Meteor.subscribe('posts', this.findOptions());
  33. },
  34. posts: function() {
  35. // console.log("is find limited to subscriptions too??");
  36. // console.log(Posts.find().count())
  37. return Posts.find({}, this.findOptions());
  38. },
  39. data: function() {
  40. // console.log('is data limited to this?')
  41. // console.log(Posts.find().count())
  42.  
  43. var hasMore = this.posts().count() === this.postsLimit();
  44. var adjustOrNot = this.posts()
  45. if (!hasMore){
  46. var nextPath = this.route.path({postsLimit: this.posts().count()});
  47. }else{
  48. var nextPath = this.route.path({postsLimit: this.postsLimit() + this.increment});
  49. }
  50. return {
  51. posts: this.posts(),
  52. ready:this.postsSub.ready(),
  53. nextPath: hasMore ? nextPath : null
  54. };
  55. }
  56. });
  57.  
  58. //...
  59.  
  60. Router.route('/:postsLimit?', {
  61. name: 'postsList'
  62. });
Add Comment
Please, Sign In to add comment