Have any package to get data from "Publish" directly?


#1

I want to get data from Publish or alternative directly

// Severe 
Meteor.pubAlternative('myPub', function (parameters ){
   var data = [];
   // do something
   ..........
   return  data;
});

// Client 
// Check pub is ready and then
.......
var getData = Meteor. subAlternative();

#2

You can publish collection which will consist of documents describing where to subscribe and on client react to changes in that 1 collection.
If you really have to react on such events thrown by server.


#3

I don’t understand, please example.


#4

If you want chunk of data on demand, create REST API and access that.
If you want collections, with pub/sub use these.


#5

My purpos, I want to generate report on server and pass data to client.


#6

If your report doesn’t change over time just use a method to send your data. If it changes over time you can do something like this.
On client:

Reports = new Mongo.Collection('reports_sub');

Tracker.autorun(function () {
  Meteor.subscribe('reports_sub', {});
});

Tracker.autorun(function () {
  console.log(Reports.findOne());
});

on server:

Meteor.publish('reports_sub', function (args) {
  var pub = this;
  var id = Random.id();
  var data = {};
  pub.added('reports', id, data);

  someEvent(function (data) {
    pub.changed('reports', id, data);
  });

  pub.ready();
});

Checkout http://docs.meteor.com/#/full/meteor_publish for further info. There is a good example there which publishes counts of a collection.


#7

You need to use a Meteor “method”. See the doc here.


#8

thanks, I will check docs for more detail.


#9

Thanks for all helping.
Now, I tried, but it is difficult to understand (not reactive).