I hope all of you know the pinterest style layout and its behaviour:
- we have collection of many (let's say 1000) products
- on page load we display only little subset of that collection (i.e. 20 first products)
- when user scrolls down and reach bottom of the page, we render next 20 products
- page is viewed by many clients, and each has its own set of displayed products
Bonus task:
- when Products collection gets new items, they are displayed on top of the page (as first items in displayed products list)
I am thinking how to program that logic in Meteor way. Let's skip user interface code, I am interested only in business logic.
I am thinking about ProductsDisplayed collection as helper, which is empty and populated by 20 products on page load, then when scrolling point is reached, I insert 20 products more from original Products collection etc.
Problems:
- how to have different ProductsDisplayed collections between clients,
- how to ask for next 20 products from Products collection, and don't get the previous ones
But maybe the whole idea about ProductsDisplayed is wrong. I would love to know what do you think!
Update!
I changed approach to using only Products collection.
server:
Meteor.publish "productsDisplayed", (number) ->
Products.find {},
limit: number
client:
Meteor.autosubscribe ->
Meteor.subscribe "productsDisplayed", Session.get('productsDisplayedNumber')
and incrementing by 20 Session 'productsDisplayedNumber' when scrolling point reached. But autosubscribe makes that the whole template is rerendered, not only the new elements. Any ideas?