Inversifyjs: Proposal: ability to use numbers in `whenTargetNamed` and numbers/symbols as tag in `whenTargetTagged`

Created on 29 Nov 2016  路  9Comments  路  Source: inversify/InversifyJS

It would be nice if you add ability to use numbers as name in whenTargetNamed and numbers/symbols as tag in whenTargetTagged

I want to use enums as names in whenTargetNamed. But current signature of this method allows only string values, so i can't use enums.

enum NodeTransformers {
    CatchClauseObfuscator,
    FunctionDeclarationObfuscator,
    FunctionObfuscator
}

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(CatchClauseObfuscator)
    .whenTargetNamed(NodeTransformers.CatchClauseObfuscator);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(FunctionDeclarationObfuscator)
    .whenTargetNamed(NodeTransformers.FunctionDeclarationObfuscator);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(FunctionObfuscator)
    .whenTargetNamed(NodeTransformers.FunctionObfuscator);

Same with whenTargetTagged. It would be nice to use as tag numbers or symbols:

const tag: symbol = Symbol();

enum NodeTransformers {
    CatchClauseObfuscator,
    FunctionDeclarationObfuscator,
    FunctionObfuscator
}

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(CatchClauseObfuscator)
    .whenTargetTagged(tag, NodeTransformers.CatchClauseObfuscator);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(FunctionDeclarationObfuscator)
    .whenTargetTagged(tag, NodeTransformers.FunctionDeclarationObfuscator);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
    .to(FunctionObfuscator)
    .whenTargetTagged(tag, NodeTransformers.FunctionObfuscator);

Most helpful comment

Released 馃帀
screen shot 2016-12-04 at 16 22 31

All 9 comments

Sounds reasonable to me. Would you like to send a PR?

I can try to do it in weekend.

Cool I will be working in other issues first but If I finish them I will also work on this. I will comment here if I'm working on it...

I made some changes and update few tests but my MacBook Air just dying on that project so very hard to write additional tests, IDE is freezes.

https://github.com/sanex3339/InversifyJS/commit/2ef3c17d975ed56e39e83272a6c39c150640a801

I can make PR with this changes, but i think this changes should be covered by additional tests.

If you send a PR I will review it and take a look to the build and test coverage 馃憤

This has been now merged into master https://github.com/inversify/InversifyJS/pull/427

When i can expect beta version with this?

Released 馃帀
screen shot 2016-12-04 at 16 22 31

Amazing, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

remojansen picture remojansen  路  3Comments

RastriginSergey picture RastriginSergey  路  3Comments

stjepangolemac picture stjepangolemac  路  5Comments

AlexanderKiriluyk picture AlexanderKiriluyk  路  4Comments

codyjs picture codyjs  路  3Comments