Closed franza closed 9 years ago
Was thought about it yesterday, and not found any reason to reject this feature.
Will implement it soon, as optional value of factory
definition property. It will be one of service
(default), function
, object
, primitive
. Also, look at this issue - its about using the same feature without definition in config.
Hey @franza!
This feature released as 0.3.2-rc0
at now. As before, install dm@next
tag.
Report if some wrong!
Its now three variants: constructor
, function
and proxy
.
@franza ping
@gobwas sorry about the delay, I'm little stuck on some urgent things in my project but I'm still interested in testing this. I hope to have time on this week.
@franza Cool, let me know when you got this =)
Hey there! I've finally tested the changes you did and it looks fantastic! You can check out the things I did here. Also, a question here, why is the third option called proxy
?
Great =)
Proxy is a factory, that does nothing on required target - basically, it just returns result of loading path (require
in node). It also, as other factories, could set properties and/or make calls on result of loading. If your path points to the module.exports = {primitive type}
the Error will be occurred.
Yeah, I see. I tested that and it works as expected, just wandering why you've picked a name like proxy
. Never mind :)
May be you could propose any better name for this? =)
Hard to say. I think I'd to continue function
, constructor
sequence I'd suggest object
. That will also reflect that module.exports = {primitive type}
won't work. Still I cannot think of a good name either.
Speaking about proxy
- does the name refers to the Proxy pattern?
No, it is not related to this pattern.
And module.exports = {primitive type}
should work. Only calls and property settings on exported value will fail.
Can we add a syntax which won't handle a function like a constructor? Maybe, a flag like
instantiate
which istrue
by default? It will say how we need to treat the dependence if it is a function.Or we can think of a parameter
useAs
which has next values:constructor
(by default),function
(to call function) andasIs
(to use dependency as is).