Predefined modules with dependencies

Solved!
Posted in General by Dave Vaughan Tue Oct 27 2015 09:27:31 GMT+0000 (UTC)·6·Viewed 1,663 times

Great tool, slowly getting the idea of it. Is it possible to specify dependencies in the modules declaration in the config phase ? I get that we can define a module and the files associated that need to be loaded, but can we also specify requirements using a previously declared module, ala requirejs ? for instance, $ocLazyLoadProvider.config({ modules: [ {name: 'Common', files: ['/app/common/Amodule.js']}, {name: 'NeedsCommon', requires/uses/deps:['Common'], files:['/app/other/Bmodule.js']} ] }); so that if a state needed "NeedsCommon" which in turn required "Common" to be loaded, we'd only have to specify the one module in the resolve. I've been trying various names incase its alread a feature, but havent stumbled on it yet.
Dave Vaughan
Oct 27, 2015

(requires/uses/deps) are supposed to be an indication of the property name that would mean "also need" where we could specify modules we've already defined.

Olivier Combe
Oct 27, 2015

If you dependency is an angular dependency, the module system will resolve it on its own.
If it's a library dependency (or an angular dependency that hasn't been downloaded yet), then no there is no system to do that right now (unless you decide to use requirejs + oclazyload for require js)

Dave Vaughan
Oct 27, 2015

Yeah REALLY trying to avoid using require also, I dont think its necessary and its the pits with fake lazyloading.

I'm referring to a module as me defining an angular module via a name and a set of files, so for instance a "localstorage" module which manages traffic to the local storage of the browser, and another module which handles injection of tokens into the http requests, lets call that "security".

If I wanted to use localstorage in security to store the tokens, then security would include the localstorage module to handle that, and I'm hoping the module definition in ocll could be set up in such a way that if something requests "security" in the resolve loading pattern it'll also grab "localstorage" if that hasnt already been loaded.

I realise I still have to set up the dependencies, in the ocll config block, but the stateconfig would be a lot clearer and cleaner if I was just loading 'security' instead of ['security', 'localstorage'] and lets face it, for many apps working there could be 5 or 6 modules listed on a state. I saw someone else ask about this and then just sorta fade out instead of explaining it better. (https://github.com/ocombe/ocLazyLoad/issues/201)

I understand this may not be catered for yet, but its only a teeny step to including another 'dependency' module if its found when it goes through the load. And no, I'm not comfortable enough in my javascript to try, I'm not even that sure the place where I think is loading is doing the loading :)

Dave Vaughan
Oct 27, 2015

oh and much respect for the swift response sir.

Olivier Combe
Oct 27, 2015

No problem :)
I understand the need, but I won't be adding new functionalities to ocLazyLoad, I've switched to Angular 2 and just don't have the time/will to keep adding new stuff to this. I'll try to keep it working by fixing bugs though.
There is a "plugin" functionality that allows you to add this kind of new things, but you'll have to find someone to code it ;-)


Olivier Combe marked this as solved
Dave Vaughan
Oct 28, 2015

Thanks for the blessing to do so, I've modified the $delegate.load to act on any modules found in an array property for a predefined module. works perfectly, just need to chuck in some cyclic dependency safeguards to stop endless loops in the case I misconfigure the module config, and I can rid myself of require. Seriously prefer this library over that on.

Markdown is allowed