Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because of how reactivity in Meteor works, there is always an application state you need to design for where the server has not yet sent the data to the client yet. You can call this the "loading" state.</p> <p>Within <code>Template</code> declarations, you must always check whether data you depend on is available. If the template does depend on data, expect it first to render empty and then to update when data arrives, since the data is a reactive data source.</p> <p>With your own functions, it's best to write them in such a way that they also depend on a reactive data source and use something like <code>Meteor.autorun</code> to make sure they're re-executed when such data sources change.</p> <p>Always put code that you want to run after the page loads inside <code>Meteor.startup</code>, or you risk not even having Meteor available when your code executes.</p> <p>Here's how I would rewrite your code:</p> <pre><code>Messages = new Meteor.Collection("messages"); if (Meteor.isClient){ Meteor.startup(function() { // anything you need to do, like subscriptions }); Template.temple.loading = function() { return Messages.find().count === 0 ? "Loading..." : ""; } Template.temple.messages = function() { var messages = Messages.find(); if (messages.count() &gt; 0) return messages; } } &lt;template name="messages"&gt; {{loading}} {{#each messages}} {{message}}&lt;br&gt; {{/messages}} &lt;/template&gt; </code></pre> <p>You don't actually need a <code>Meteor.subscribe</code> call to messages if you're just using <code>Messages.find()</code> on the client.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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