Structuring methods (circular imports)


Hi all,

I’m wondering how to better structure my code. I’m using mantra with a small modification: instead of creating stubs for every method, I created a methods object which contains ValidatedMethods and attached it to the collections, i.e.:

in /lib/collections/items.js

const Items = new Mongo.Collection('items');
Items.methods = {};
Items.methods.doSomething = new ValidatedMethod({});

It looked good, but now this file became quite large. Since I need to use the Collection itself inside the methods (e.g. for inserting documents), I’m not sure how could I move out the methods object into another file and then import it in /lib/collections/items.js becase I can’t import items.js in it (otherwise it will be a circular import).

How would you solve this?