Reputation: 1529
I've a publication which sends limited number of records based on start
and limit
Metero.publish("posts",function(start,limit){
return Posts.find({},{"start":start,"limit":limit});
});
I'm subscribing to the publish function in autorun
function.
My problem is I already have few records of posts
collection in client which is used by another table
the current publish function may have records that already existed in client
I just want to know the records that are sent by the current publish function.
Any hacks or work arounds are also welcome.
EDIT I want to display those records which are published in a table, as I already have some data in client It is tought to filter out what records are sent to the client by the publish function
Upvotes: 1
Views: 144
Reputation: 1529
I ended up using 'client side collections' with custom publications for different tables
Upvotes: -1
Reputation: 11376
Try this publish function,
Meteor.publish('posts', function(limit) {
if (limit > Posts.find().count()) {
limit = 0;
}
return Posts.find({ },{limit:limit});
});
now on the 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 helper on some each helper
<template name="Posts">
{{#each posts}}
{{namePost}} <!-- or whatever register on the posts mongo document -->
{{/each}}
<!-- button to load more posts -->
<button class="give-me-more">Click for more posts </button>
</template>
now if you want to increment the number of post by 10 x 10 use this function
incrementLimit = function(inc=10) {
newLimit = Session.get('limit') + inc;
Session.set('limit', newLimit);
}
and call it on a click event like this
Template.Posts.events({
'click .give-me-more': function(evt) {
incrementLimit();
}
});
Now each time the posts template its created you will get only 10 posts on each template you use this helper, and load 10x each time button its clicked
This is the same code from Gentlenode
i just added the HTML, hope this help you
Upvotes: 2
Reputation: 1268
Have you considered logging it to the console?
Metero.publish("posts",function(start,limit){
var currentPosts = Posts.find({},{"start":start,"limit":limit});
console.log(currentPosts);
return currentPosts;
});
Upvotes: 0