How do you use Coffeescript global variables when starting a client in Meteor?

As lib.coffeeI have @x = 1. As client.coffeeI have Meteor.subscribe('data', x). When the page loads, I get an error in the console:

Uncaught ReferenceError: x is not defined

However, after the page has finished loading and entering the type xin the console, it is recognized as a global variable with a value of 1.

+4
source share
1 answer

It is related to the order in which the source files are evaluated. For all the details, carefully read the this section in the docs. You can play a series of games with file names and locations to change the order in which they are downloaded:

  • ,
  • ,
  • , lib

, , , - :

Meteor.startup ->
  Meteor.subscribe 'data', x

Tracker.autorun ->
  if Meteor.userId()
    Meteor.subscribe 'data', x

, .

+4

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


All Articles