Global Closing Meteor Collection for Coffeescript

If I declare a global collection, as shown below:

@Matches = new Meteor.Collection "Matches" 

How can I find a consistent way to access it in closure on both the server side and the client side of Meteor?

For example, the following does not work, since @ refers to this (which is not the top-level namespace in the closure)

 Meteor.publish("current-matches", -> return @Matches.find(round: 0) # @Matches doesn't work since `this` is something else ) 
+4
source share
1 answer

Put the definitions of your collection in a shared directory so that they are visible to both the client and the server. Then you can use them without @ . For instance:

collections /matches.coffee

 @Matches = new Meteor.Collection 'matches' 

server /server.coffee

 Meteor.publish 'current-matches', -> Matches.find round: 0 
+6
source

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


All Articles