Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate the references #6

Open
antonioaltamura opened this issue Apr 24, 2016 · 1 comment
Open

propagate the references #6

antonioaltamura opened this issue Apr 24, 2016 · 1 comment

Comments

@antonioaltamura
Copy link

antonioaltamura commented Apr 24, 2016

Hi, it would be very helpful if the module 'propagates' the variables defined in it in the node.js environment.
Il'l explain better:
in your base example you wrote

var requireFrom = require('requirefrom')
var views = requireFrom('lib/components/framework/views/')

but it would be VERY helpful if 'views' would be visible in all the other node.js scripts (obiouvsly requiring "requirefrom"). What do you think?

@dskrepps
Copy link
Owner

Perhaps you should instead consider Dependency Injection. This is when you write your modules as a function (or "factory") that encompasses the module's methods, and that factory accepts the dependencies (views in that example) as it's arguments.

Here are a couple simple examples:
https://blog.risingstack.com/fundamental-node-js-design-patterns/#dependencyinjection
http://stackoverflow.com/a/36771139

'views' in your question is an object like any other that can be injected into your modules, or assigned to some application object that is passed to all your modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants