Name: meteor-subscription-data
Owner: PeerLibrary
Description: Reactive and shared subscription data context
Created: 2015-12-20 18:02:38.0
Updated: 2017-09-10 19:23:41.0
Pushed: 2018-02-25 11:35:55.0
Homepage: https://atmospherejs.com/peerlibrary/subscription-data
Size: 22
Language: CoffeeScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This Meteor smart package provides a reactive and shared (between client and server side) subscription data context. When you subscribe to a publish endpoint, a reactive data context is established which can be read and changed both on the client or server side to provide alternative (reactive) way of passing arguments to the publish endpoint, without subscription restarting. To be useful, use peerlibrary:reactive-publish and server-side autorun in your publish endpoint function to react to data context changes.
Adding this package to your Meteor application extends
publish endpoint function's this
and subscription's handle with data
and setData
methods.
Both client and server side.
or add peerlibrary:subscription-data
The subscription handle returned from Meteor.subscribe
contains two new methods:
data(path)
? returns current data context object; if path
is specified, returns value under path
in the data
context; it uses data-lookup package to resolve the pathsetData(path, value)
- sets the value under path
in the data context object to value
; if value
is undefined
,
path is unset; alternatively, you can pass the whole new data context object which will be used as the new data contextSame methods are available also inside the publish endpoint function
through this
.
If on the server side you have such publish endpoint:
or.publish('infinite-scroll', function () {
r self = this;
lf.autorun(function (computation) {
self.setData('countAll', MyCollection.find().count());
;
lf.autorun(function (computation) {
var limit = self.data('limit') || 10;
// Do not forget to check the data.
check(limit, Number);
return MyCollection.find({}, {limit: limit, sort: {timestamp: -1}});
;
Then you can on the client side subscribe to it and control it without restarting the subscription:
subscription = Meteor.subscribe('infinite-scroll');
eturns the count of all documents in the
ollection, even if only a subset is published.
cription.data('countAll');
ets a new limit for published documents. Only the extra documents
re send to the client and subscription does not restart.
cription.setData('limit', 20);