requireFrom icon indicating copy to clipboard operation
requireFrom copied to clipboard

propagate the references

Open antonioaltamura opened this issue 9 years ago • 1 comments

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?

antonioaltamura avatar Apr 24 '16 01:04 antonioaltamura

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.

dskrepps avatar Apr 24 '16 06:04 dskrepps