peerlibrary/meteor-subscription-data

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

subscription data context

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.

Installation
or add peerlibrary:subscription-data
API

The subscription handle returned from Meteor.subscribe contains two new methods:

Same methods are available also inside the publish endpoint function through this.

Examples

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);

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.