Created
April 21, 2016 11:44
-
-
Save christianalfoni/34775b1274263b2f5289ac9ff4403b28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ModulesProvider(context, execution, controller) { | |
var modules = controller.getModules(); | |
var services = controller.getServices(); | |
context.modules = Object.keys(modules).reduce(function (contextModules, key) { | |
var modulePath = key.split('.'); | |
var module = modulePath.reduce(function (contextModules, pathKey) { | |
contextModules[pathKey] = contextModules[pathKey] || {}; | |
return contextModules[pathKey]; | |
}, contextModules); | |
module.meta = modules[key]; | |
module.state = context.state.select(modulePath); | |
module.services = modulePath.reduce(function (services, key) { | |
return services[key] || {}; | |
}, services); | |
if ( | |
execution.options.modulePath && | |
execution.options.modulePath.join('.') === key) { | |
context.module = module; | |
} | |
return contextModules; | |
}, {}); | |
return context; | |
} | |
function SomeAction({module, modules}) { | |
module.state.set('foo', 'bar'); | |
module.services.foo(); | |
module.meta // {path,name, ...} | |
modules.someOtherModule.state('foo', 'bar'); | |
modules.someOtherModule.services.foo(); | |
modules.someOtherModule.meta // {path,name, ...} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment