vazco / universe-modules

Use ES6 / ES2015 modules in Meteor with SystemJS
https://atmospherejs.com/universe/modules
MIT License
52 stars 7 forks source link

Question : General Question about Modules and this Package #31

Closed rwatts3 closed 8 years ago

rwatts3 commented 8 years ago

Greetings,

First and foremost thank you for producing this package. I am still learning some of the new features for ES6 so I apologize in advance if this question is a bit rudimentary.

If I were to take a file and turn it into a component, such as a mongo collection with a simple schema using aldeed's simple schema.

Does this mean everywhere in my application that I want to use data from this collection, I must use System.import. Or am I still able to use Templating in some other file, or must the importation of the component come before my Meteor Template logic.

MacRusher commented 8 years ago

Depends of how you structure your application.

Assuming you have a module that exports a collection, e.g.

const Example = new Mongo.Collection('example');
// some SimpleSchema code etc
export default Example;

Then inside another module you can write

import Example from '/path/to/Example'
let examples = Example.find().fetch();

But if your code is inside "normal" files that are not parsed by our package (which may work for you better when using Blaze) then you have to use dynamic loading with promises:

System.import('/path/to/Example').then(module => {
    const Example = module.default;
    let examples = Example.find().fetch();
});