Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor where to define my collection?

Tags:

meteor

I have a pretty simple app structure that contain those libs

server - contain some configuration for routing and ENV

client - contain templates (<template name=".*"></template>) & JS File for every template

collections

now inside collections i have file called "Albums.js" and has a pretty simple content

var Albums = new Meteor.Collection("Albums");

now inside my client folder i'm trying to access to this variable Albums and i'm get undefined error.

my target is to take data from form and pass it to collection.insert

like image 366
Yochai Akoka Avatar asked Jul 13 '13 08:07

Yochai Akoka


3 Answers

Do not use var unless you want it private to that file.

Albums = new Meteor.Collection("Albums");

like image 117
Steeve Cannon Avatar answered Oct 28 '22 12:10

Steeve Cannon


another way to define global variables is to create new file, e.g. collections.js and put it directly into Your app root folder (not into any subfolder!)

In this file You can define global variable/collection (without var keyword)

like image 5
lukaszkups Avatar answered Oct 28 '22 13:10

lukaszkups


Variables defined with var keyword are local to the file they're defined in. If you want a global variable, shared across files, you need to define it without the var keyword.

It looks like it's not in the doc, but it's in the https://github.com/meteor/meteor/blob/master/History.md file (for version 0.6.0):

Variables declared with var at the outermost level of a JavaScript source file are now private to that file. Remove the var to share a value between files.

Basically, each JS file is wrapped in the (function(){ ... })(); pattern to provide this encapsulation.

like image 4
Hubert OG Avatar answered Oct 28 '22 13:10

Hubert OG