I run into this same problem quite often. First, I create a namespace and then add modules to this namespace. Then issue I always run into is how best to initialize the application? Naturally, each module has its own startup procedure so should this data(not code in some cases, just a list of items to run) stay with the module? Or should there be a startup procedure in the global namespace which has the startup data for ALL the modules.
Which is the more robust way of organizing this situation? Should some things be made centralized or should there be strict adherence to modules encapsulating everything about themselves?
Though this is a general architecture questions, Javascript centric answers would be really appreciated!
3
Some data/scope is always given for any module, because they all run as part of the same application. It doesn’t make sense to let every module load this for itself.
But if you distribute aliases for the data between modules, you can get into trouble. (Race conditions etc.). So be careful.
It all depends on your needs what your script will do. You may call the procedure which will initialize the data for all listed modules then it may occur that by now you required no manipulation on data and but later on future it is demanded. And yes the race condition as stated above may bring you in trouble. So I recommend first analyze your script how’s the flow in operation and there by decide how to make initialization.
OSGi is a framework used for inter-module communication. You can set up your modules to write/read from/to the osgi service, and hence setting up a channel to exchange data between modules.
Can this be done in Java script ? I am not sure but a google search does throw up a few interesting links which can be further explored