Difference between PubSub and methods

What's the difference between PubSub and Methods in Meteor ?!

Can I put methods in a Server folder, such as Publish?

It seems to me too, but the methods are more reactive.

+3


source to share


2 answers


They are two different sides of the same coin. Here's a drawing of the data lifecycle in meteor:

Meteor Data Lifecycle



  • Publish - what data is sent from the server
  • Subscribe - what data the client requests publications for
  • Methods - How to manipulate data from client to server
    • Note . This usually runs on both the client and the server. The client will make a prediction of what the server will do so that it can update immediately. Then the delay compensation will be triggered when the method is running on the server and the canonical decision will be made.
+6


source


What's the difference between PubSub and methods in Meteor ?!

Publications are reactive and they provide a cursor. Subscription allows you to get the corresponding client-side publication in minimongo database. Methods, on the other hand, have to be called instead of subscribed, and they are mainly intended to perform server-side tasks that you don't want to handle on the client-side for many possible reasons.

More details here for publications: https://www.discovermeteor.com/blog/understanding-meteor-publications-and-subscriptions/

But for the methods: http://meteortips.com/first-meteor-tutorial/methods/



Can I put methods in a Server folder, such as Publish?

Yes, you can and should. For example, put them inserver\methods

It seems to me too, but the methods are more reactive.

This is exactly the opposite. They are not the same, even if you can achieve the same results with both. Methods by design are unresponsive and pub / sub is.

+3


source







All Articles