{"action":"created","issue":{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/471","labels_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/471/labels{/name}","comments_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/471/comments","events_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/471/events","html_url":"https://github.com/aldeed/meteor-simple-schema/issues/471","id":111022384,"number":471,"title":"problems creating global Schema object","user":{"login":"lyricalpolymath","id":516744,"avatar_url":"https://avatars.githubusercontent.com/u/516744?v=3","gravatar_id":"","url":"https://api.github.com/users/lyricalpolymath","html_url":"https://github.com/lyricalpolymath","followers_url":"https://api.github.com/users/lyricalpolymath/followers","following_url":"https://api.github.com/users/lyricalpolymath/following{/other_user}","gists_url":"https://api.github.com/users/lyricalpolymath/gists{/gist_id}","starred_url":"https://api.github.com/users/lyricalpolymath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyricalpolymath/subscriptions","organizations_url":"https://api.github.com/users/lyricalpolymath/orgs","repos_url":"https://api.github.com/users/lyricalpolymath/repos","events_url":"https://api.github.com/users/lyricalpolymath/events{/privacy}","received_events_url":"https://api.github.com/users/lyricalpolymath/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-12T17:43:25Z","updated_at":"2015-10-13T15:40:49Z","closed_at":"2015-10-13T15:40:49Z","body":"Hello, first of all thanks for the great packages.\r\n\r\nI'm having a hard time creating a global Schema object \r\n\r\nif I create in \r\n`/common/models/SomeCollection.js`\r\nthe following code \r\n\r\n```\r\nif (Schemas == undefined) {\r\n    //global schemas is undefined > create it\r\n    Schemas = {};\r\n}\r\n\r\n//a schema that will end in global but not to \r\n\r\n//register the schema in the global object\r\nSchemas.SomeSchema = new SimpleSchema({ ... });\r\n\r\n//assign the schema\r\nSomeCollection.attachSchema(Schemas.SomeSchema);\r\n```\r\n\r\nI always get this `ReferenceError: Schemas is not defined`\r\n```\r\nW20151012-19:11:16.092(2)? (STDERR) \r\nW20151012-19:11:16.092(2)? (STDERR) /Users/b/.meteor/packages/meteor-tool/.1.1.4.1d1i42q++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245\r\nW20151012-19:11:16.092(2)? (STDERR)                                             throw(ex);\r\nW20151012-19:11:16.092(2)? (STDERR)                                                   ^\r\nW20151012-19:11:16.092(2)? (STDERR) ReferenceError: Schemas is not defined\r\nW20151012-19:11:16.092(2)? (STDERR)     at app/common/SomeCollection.js:3:44\r\nW20151012-19:11:16.093(2)? (STDERR)     at app/common/SomeCollection.js:7:3\r\nW20151012-19:11:16.093(2)? (STDERR)     at /Users/xxxxx/Documents/projectDir/.meteor/local/build/programs/server/boot.js:222:10\r\nW20151012-19:11:16.093(2)? (STDERR)     at Array.forEach (native)\r\nW20151012-19:11:16.093(2)? (STDERR)     at Function._.each._.forEach (/Users/xxxxx/.meteor/packages/meteor-tool/.1.1.4.1d1i42q++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)\r\nW20151012-19:11:16.093(2)? (STDERR)     at /Users/xxxxx/Documents/projectDir/.meteor/local/build/programs/server/boot.js:117:5\r\n```\r\n\r\n\r\nI keep getting the ReferenceError even after trying all these solutions:\r\n- checking if it is undefined and create it only afte that\r\n- checking the precedence of execution of the files\r\n- creating the global object in a Meteor.startup, but that gets executed after\r\n- changing the 'Schemas' variable name to something that might not be reserved for some reason\r\n- creating the Schemas as a new Object\r\n- adding Schemas.prototype.SomeSchema instead of Schemas.SomeSchema\r\n\r\nnone work...\r\nI really don't understand why... also because all other variables like SomeCollection, and even other new SimpleSchemas like the baseschema in [this similar issue](https://github.com/aldeed/meteor-simple-schema/issues/79) do end up in the global scope.\r\n\r\nany ideas?\r\n"},"comment":{"url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/comments/147754404","html_url":"https://github.com/aldeed/meteor-simple-schema/issues/471#issuecomment-147754404","issue_url":"https://api.github.com/repos/aldeed/meteor-simple-schema/issues/471","id":147754404,"user":{"login":"lyricalpolymath","id":516744,"avatar_url":"https://avatars.githubusercontent.com/u/516744?v=3","gravatar_id":"","url":"https://api.github.com/users/lyricalpolymath","html_url":"https://github.com/lyricalpolymath","followers_url":"https://api.github.com/users/lyricalpolymath/followers","following_url":"https://api.github.com/users/lyricalpolymath/following{/other_user}","gists_url":"https://api.github.com/users/lyricalpolymath/gists{/gist_id}","starred_url":"https://api.github.com/users/lyricalpolymath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyricalpolymath/subscriptions","organizations_url":"https://api.github.com/users/lyricalpolymath/orgs","repos_url":"https://api.github.com/users/lyricalpolymath/repos","events_url":"https://api.github.com/users/lyricalpolymath/events{/privacy}","received_events_url":"https://api.github.com/users/lyricalpolymath/received_events","type":"User","site_admin":false},"created_at":"2015-10-13T15:40:49Z","updated_at":"2015-10-13T15:40:49Z","body":"I found a solution,\r\nI still don't understand why this was happening only with the Schemas object,\r\nbut at least it doesn't print out annoying warnings.\r\n\r\nTo solve the issue put the following lines in the first file that needs the global Schemas\r\n\r\n```\r\nif(typeof Schemas === \"undefined\") {\r\n    Schemas = function Schemas() {}\r\n}\r\n```\r\n\r\nafter this Schemas will be globally accessible by all other subsequently loaded files.\r\n\r\nIt is safe to add those lines to the beginning of all files who use the Schemas object, in case you decide to rename it and the order changes.\r\n\r\n"}}