Difference between PubSub and Methods

感情迁移 提交于 2019-12-05 01:13:32

问题


What is the difference between PubSub and Methods in Meteor?!

Can I put Methods in Server folder like Publishs?

To me seen like the same, but Methods is more reactive.


回答1:


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

  • Publish - Which data is sent from the server
  • Subscribe - Which data the client requests publications for
  • Methods - How to manipulate data from the client on the server
    • Note - this will typically be run on both on the client and the server. The client will make a prediction as to what the server will do so it can update right away. Then latency compensation will kick in when the method is run on the server and the canonical decision is made.



回答2:


What is the difference between PubSub and Methods in Meteor?!

Publications are reactive and they provide a cursor. Subscription gets you the matching publication on clientside in a minimongo database. On the other hand, methods must be called instead of subscribed and they are mainly designed to execute server side tasks that you don't want to handle client side for many possible reasons.

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

And here for methods: http://meteortips.com/first-meteor-tutorial/methods/

Can I put Methods in Server folder like Publishs?

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

To me seen like the same, but Methods is more reactive.

This is the exact contrary. They are not the same, even if you can achieve similar results with both. Methods are by design not reactive, and pub/sub are.



来源:https://stackoverflow.com/questions/31589216/difference-between-pubsub-and-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!