SmartQuery
Getting rid of publish()
and subscribe()
Usage
Just call SmartQuery.create()
inside a regular template helper. For example:
1Template.posts.helpers({ 2 posts: function () { 3 var cursor = Posts.find({}, {limit: Session.get("postsLimit")}); 4 return SmartQuery.create("posts", cursor); 5 } 6}
SmartQuery.create(id, cursor)
id
: a unique id for this particular SmartQuery.cursor
: the cursor you want to use (e.g.Posts.find({}, {limit: 5})
).
Returns an object with the following properties:
subscription
: the subscription created for this SmartQuery.cursor
: the cursor you passed to the SmartQuery.isReady()
: (function) whether the subscription is ready (Boolean).count()
: (function) returns a count of the cursor.totalCount()
: (function) returns the total count for the cursor on the server (without alimit
).hasMore()
: (function) whether there are more documents on the server (Boolean).