Try this publish feature,
Meteor.publish('posts', function(limit) {
if (limit > Posts.find().count()) {
limit = 0;
}
return Posts.find({ },{limit:limit});
});
now on client.js
Template.Posts.created = function() {
Session.setDefault('limit', 10);
Tracker.autorun(function() {
Meteor.subscribe('getPosts', Session.get('limit'));
});
}
now you can use this helper,
Template.Posts.helpers({
posts: function() {
return Posts.find({ }, { limit: Session.get('limit') });
}
});
and using it like any normal assistant on each of the assistants
<template name="Posts">
{{#each posts}}
{{namePost}}
{{/each}}
<button class="give-me-more">Click for more posts </button>
</template>
now if you want to increase the number of posts by 10 x 10 use this function
incrementLimit = function(inc=10) {
newLimit = Session.get('limit') + inc;
Session.set('limit', newLimit);
}
and call it a click event like this
Template.Posts.events({
'click .give-me-more': function(evt) {
incrementLimit();
}
});
Now every time the created message template is created, you will receive only 10 messages on each template that you use this helper, and download 10 times each button by pressing the button
This is the same code from Gentlenode
HTML, ,