gobwas / dm.js

Javascript Dependency Injection Manager
MIT License
108 stars 4 forks source link

Add syntax for just requiring path #35

Closed gobwas closed 9 years ago

gobwas commented 9 years ago

{ "calls": ["<./path/to/module.js>"] }

gobwas commented 9 years ago
franza commented 9 years ago

This issue should not be closed since dm.js still doesn't support injecting a module like a single structure. Since issue#36 already has a feature to refer module properties using JSON, why don't we use same syntax to inject the whole exported object. For example:

//module.js
module.exports = { /* ... */ };

//app.js
var config = {
  "module": {
    "path": "./module#"
  }
}

Since # is used as a separator between module path and JSON Pointer syntax, an empty string that follows after # says that we need to select the whole JSON document.

gobwas commented 9 years ago

But this logic must already work :) did you tried it?

gobwas commented 9 years ago

Aw, I understand, at now path is a path to the constructor. The question is why u want to configure simple object/function like service definition?

franza commented 9 years ago

No it doesn't. In my test project it didn't work, I can't remember why, I'll put some details later.

franza commented 9 years ago

To add some flexibility to use modules. There can be a situation in which you may want to use a plain object containing a bunch of function. Something like a Singleton. Also, you may want to export a single function which should be used without new keyword as factories or as strategies. Do the main point is not to limit users with constructors.

gobwas commented 9 years ago

Did this fits?