If using the imports/ directory then you may have to manually import the subclasses still so that they are included in the bundle (in non-circular code)
Thanks for the suggestion, but I’m trying to write native ES6 code (I don’t want to come back to it in a few year and face the same problem when Meteor stops transpiling code to ES5).
I think I’ll just create a new class in a new file and put getNewRandomSubClassInstance in that one. I guess the code will be better structured this way, but I get the feeling it will make life harder for the programmer (yet another class).
I don’t remember the work around I used in this particular case, but the solution includes restructuring the code somehow, for example in the way I wrote in my earlier post.
An easier workaround, taking advantage of ES Module circular import resolution semantics is to add the static method after the class is defined:
import { SubClass1 } from './SubClass1'
import { SubClass2 } from './SubClass2'
export const SuperClass = class {
// ...
}
SuperClass.getNewRandomSubClassInstance = function() {
if (godIsHappy()) {
return new SubClass1()
} else {
return new SubClass2()
}
}
This way, when the sub-classes import the super class, the class without the static method is returned to them, and after the sub-classes have finished loading the static method(s) are added.
This works because classes are just sugar over objects and prototypes, and a static method is basically just a function on an object