Where should Meteor.methods() be defined?

后端 未结 4 702
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 15:31

http://docs.meteor.com/#meteor_methods

I have tried it in publish.js in my server folder.

I am successfully calling Meteor.apply and attempting the server ca

4条回答
  •  感情败类
    2020-12-13 15:58

    There are several places I can define my Meteor.methods() (with pro's and con's):

    1. On the server only - when the client calls the method, it'll have to wait for the server to respond before anything changes on the client-side
    2. On the server, and uses a stub on the client - when the client calls the method, it will execute the stub method on the client-side, which can quickly return a (predicted) response. When the server comes back with the 'actual' response, it will replace the response generated by the stub and update other elements according.
    3. The same method on both client and server - commonly used for methods dealing with collections, where the method is actually a stub on the client-side, but this stub is the same as the server-side function, and uses the client's cached collections instead of the server's. So it will still appear to update instantly, like the stub, but I guess it's a bit more accurate in its guessing.

提交回复
热议问题