Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Generically Typed Implementations #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dwelch2344
Copy link

Brought us up to the 0.5.0 cut of rtti, and added a first stab at supporting generic tokens.

Probably a much smarter way of both creating the provider + resolving the tokens, but I was able to "break all teh tests" and then repair them with this simple approach.

Def open to feedback. But it's working on my use case really nicely, so gives me hope :)

package.json Outdated Show resolved Hide resolved
src/injector.ts Outdated Show resolved Hide resolved
src/injector.ts Outdated Show resolved Hide resolved
src/injector.ts Outdated Show resolved Hide resolved
@@ -21,7 +21,8 @@
"mock"
],
"dependencies": {
"typescript-rtti": "^0.4.16"
"deep-equal": "^2.0.5",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I don't need this here


// if it's a generic ref, lookup the specific match we put in the map
if( token instanceof ReflectedGenericRef && token.isGeneric()){
token = this.#generics.find(t => t.matchesRef(token)) || token
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming matchesRef(..) works out, we can essentially resolve the token here with a simple list of generic tokens, then let things play out as normal :)

@@ -206,6 +223,9 @@ export class Injector {
return { tokens: [ typeRef.token ] };
else if (typeRef.isLiteral())
return { tokens: [ typeRef.value.constructor ]}
else if (typeRef.isGeneric() )
// TODO: ask @rezonant for a better way to handle this
return { tokens: [ typeRef ]}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking this is good now. Essentially we support the ref itself as an actual token (and presume our token resolution will unify different instances)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants