I have two classes in ES6 that need each other. The code is here (I'm using Meteor.js);
export class Activity {
constructor(doc) {
_.extend(this, doc);
}
getSubActivities() {
return Activities.find({ parent: this._id }).fetch();
}
}
class ActivitiesCollection extends Mongo.Collection {
/* nothing relevant */
}
export const Activities = new ActivitiesCollection('appjournalActivities', {
transform(doc) {
return new Activity(doc);
},
});
The code works properly. But the linter does not like that I use Activities
before it has been defined (error description at eslint.org).
Am I using a wrong pattern/code structure? Is there a standard solution in ES6?
One solution is the following (it works):
export let Activities = null;
/* code as before */
Activities = new ActivitiesCollection('appjournalActivities', {
/* code as before */
But I do not like it very much.