fjorgemota / jimple

Just a dependency injection container to NodeJS and to the browser using new ES6 features
MIT License
75 stars 12 forks source link

Handle GeneratorFunction properly #6

Closed alxarch closed 8 years ago

alxarch commented 8 years ago

Currently GeneratorFunction objects are passing like normal function objects. The check Object.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:

fjorgemota commented 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!

alxarch commented 8 years ago

The current isFunction that is being used returns true for GeneratorFunction also

fjorgemota commented 8 years ago

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.

fjorgemota commented 8 years ago

Fixed!

Thanks, @alxarch!