Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading message during template redraw in Meteor
    primarykey
    data
    text
    <p>I built my first Meteor app and I love it. Except, now that it has real production data in it, it's a little slow. I'm getting reports that "nothing is happening when I click this".</p> <p><strong>Is there any way to display a loading message during template redraws so that the user knows something is happening?</strong></p> <p>To illustrate further, look at this template (not my actual code, for simplicity only):</p> <pre><code>Template.all_posts.posts = function() { return Posts.find({'category_id': Session.get('current_category')}); } </code></pre> <p>So if open my console and run <code>Session.set('current_category', 1)</code>, and let's say it takes 2 seconds to run the computation and redraw the templates. I'd like there to display a loading indicator during that 2 second period.</p> <p>To be clear, I already know how to display a loading indicator. In fact, I'm already do that on initial page load and hiding it when all my subscriptions are <code>ready()</code>. I simply want to know where to apply that same logic (showing and hiding loading icon) so that it will happen every time the templates are redrawn. Pseudo code would work fine:</p> <p><strong>In short, when Meteor is busy, I want to reflect that.</strong></p> <p>Any help is greatly appreciated!</p> <p><strong>Edit 10/09/13:</strong></p> <p>From the docs...</p> <blockquote> <p>These Meteor functions run your code as a reactive computation:</p> <ul> <li>Templates</li> <li>Meteor.render and Meteor.renderList</li> <li>Deps.autorun</li> </ul> </blockquote> <p>I think one possible solution could <em>begin</em> with displaying a loading indicator when any of these "computations" are invalidated. </p> <p>For example, if you're code is being run inside of <code>Deps.autorun</code>, the computation instance is passed as the first argument and you can pass a callback to it's <code>onInvalidate</code> method, like so:</p> <pre><code>Deps.autorun(function(computation) { // do reactive stuff computation.onInvalidate(function() { // display loading indicator }); }); </code></pre> <p>However, to my knowledge, you cannot access the computation object in those other Meteor methods, only <code>Deps.autorun</code>.</p> <p>As far as hiding the loading indicator, I think the best idea would be to do it <em>inside the <code>rendered</code> callback of the last template to be (re)rendered</em> due to the invalidation of the computation.</p> <p><strong>Anyone have any insights, suggestions, tricks, hacks, etc. into this?</strong></p>
    singulars
    1. This table or related slice is empty.
    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.
    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