In Meteor, how to determine which session variable causes a pattern to repeat

This is a general question about designing meteorite applications or debugging meteor applications.

When I write meteorite applications, I usually update the values ​​of the session variables to cause the auxiliary function of the template to re-execute and / or to re-display the template. So my application has quite a few different session variables.

Sometimes I find that a helper function is re-running several times, but I cannot think of any reason why it is re-running so many times. Some session variable must be updating and causing a restart. Is there any way to figure out which session variable is causing it?

General question: in reactive design, when I see that a template gets re-rendered, how can I find why it gets re-rendered?

+4
source share
1 answer

You can use Deps.autorun to quickly determine what it is if you want to quickly debug its quick way to do

Paste the code e.g.

Deps.autorun(function() {
   Session.get("something");
   console.log("Session something has changed");
});

Deps.autorun(function() {
   Meteor.user()
   console.log("Meteor user has changed");
});

You can place such blocks of code on your client computer to see what is changing. Each of them will be launched once, first, and then after each change of the reactive variable inside it.

You will need to do this for each variable that you use in your template, and this will help you find out what is changing, each Deps.autorun block will work independently only if the variable inside it changes.

+1

Source: https://habr.com/ru/post/1543772/


All Articles