Closed alxarch closed 8 years ago
hmm...
I'm not sure if something like that it's needed at all. I don't think that a GeneratorFunction should be used ideally as a service, because...it does not make sense. A factory is a function that is called repeatedly, and I think that it should not maintain state at all, so...a GeneratorFunction as a factory does not make sense to me. Another point is that a Generator eventually can end, so...how a factory using a GeneratorFunction should treat this?
For me, seems obvious that the user can put on anything he wants as a service/parameter, but treating it directly into the library does not make sense in the context o Dependency Injection.
However, can you provide examples for that use case? It maybe be useful to discuss these type of problems..
Thanks!
The current isFunction
that is being used returns true
for GeneratorFunction
also
hmmm..Good catch. I did not have noted that. Thanks for reporting it!
So...I think that generators should be parameters, but I'm really not sure of what to do in this case. I'll think more and probably fix it soon. Anyway, suggestions are appreciated in the mean time.
Fixed!
Thanks, @alxarch!
Currently
GeneratorFunction
objects are passing like normalfunction
objects. The checkObject.prototype.toString.call(fn)
returns'[object Function]'
in both cases. When a service is retrieved the instance is a generator object which is not probably correct. The solutions I can think of are:GeneratorFunction
as simple parameter and not as service (ietypeof fn === 'function' && fn.constructor.name === 'Function
)Factories
could be implemented with a generator byyield
ing results every time the service is asked for and implementJimple#factory()
with afunction *(c) { while(true) yield fn(c); }
)