Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to use Meteor.methods and utilizing stubs
    primarykey
    data
    text
    <p>Using Meteor, I'm attempting to understand when to use server-side <code>Meteor.methods()</code> while still retaining instant UI updates. </p> <p>From Andrew Scala's <a href="http://andrewscala.com/meteor/" rel="noreferrer">introductory tutorial</a>, he claims that <code>Meteor.methods()</code> should be used when you want to update and modify your database documents: </p> <blockquote> <p>The idea is that you define all the functions on the server that do dangerous stuff like modify and update data, and then let the client call those functions and get return values like regular functions. The client never sees the implementation and doesn’t personally modify the data. The server does all the work.</p> </blockquote> <p>And following this advice, I implemented this in my code: </p> <p>Server-side: </p> <pre><code>Meteor.methods({ addMovie: function(data) { var movie = Movies.insert({name: data}); return movie; }, ... </code></pre> <p>Client-side: </p> <pre><code>Template.movies.events = ({ 'click #add-movie': function(e) { var name = document.getElementById('movie-name').value; Meteor.call('addMovie', name); return false; }, ... </code></pre> <p>This works, but it's slow. The UI doesn't update instantly like it would if you called <code>Movies.insert()</code> on the client-side. The <a href="http://docs.meteor.com/#meteor_methods" rel="noreferrer">docs</a> indicate that, to rectify the problem, you can create stubs on the client-side: </p> <blockquote> <p>Calling methods on the client defines stub functions associated with server methods of the same name. You don't have to define a stub for your method if you don't want to. In that case, method calls are just like remote procedure calls in other systems, and you'll have to wait for the results from the server.</p> </blockquote> <p>But what should these stubs look like? Should it basically look the same as the server-side method? If so, what's the point? I'm looking for a more comprehensive explanation of the use and purpose of <code>Meteor.methods()</code>, the point/use of stubs, and their implementation. </p> <p><strong>EDIT: David Greenspan has helped clarify the use of Meteor.methods() and stubs on <a href="https://groups.google.com/forum/#!topic/meteor-talk/BB-AfAYY52g" rel="noreferrer">meteor-talk</a>.</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload