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
Add support for property dependency injection #292
Conversation
4144ad1
to
9f8c91f
Compare
@@ -22,7 +22,8 @@ describe('function argument injection', () => { | |||
} | |||
|
|||
const meta = describeInjectedArguments(TestClass); | |||
expect(meta).to.deepEqual(['foo']); | |||
expect(meta.length).to.eql(1); | |||
expect(meta[0].bindingKey).to.deepEqual('foo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(meta.map(m => m.bindingKey)).to.deepEqual(['foo']);
This way the assertion error message can include extra keys when the meta has more than one entry.
} | ||
} | ||
|
||
let t = instantiateClass<TestClass>(TestClass, ctx) as TestClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the TypeScript compiler should be able to infer the specialisation of instantiateClass
from the first argument:
let t = instantiateClass(TestClass, ctx) as TestClass;
Could you please double check?
If I am right, then the same simplification should be applied to most of the other tests below too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we should prefer const
over let
, I am surprised tslint
did not complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note the return type of instantiateClass
is T | Promise<T>
. We have to cast it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good, I left few comments to address.
|
||
let t = instantiateClass<TestClass>(TestClass, ctx) as TestClass; | ||
expect(t.foo).to.eql('FOO'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line, please remove.
Same comment applies to other test cases in this file too.
Haha, tslint did catch that, see the output of Travis CI for an example (link). Please fix your code to pass |
9f8c91f
to
9c372fb
Compare
@bajtos Comments addressed. PTAL. |
12d0f0f
to
245311d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there :)
I found few inconsistencies in the code, PTAL 👇
packages/context/src/inject.ts
Outdated
export function inject(bindingKey: string, metadata?: Object) { | ||
// tslint:disable-next-line:no-any | ||
return function markArgumentAsInjected(target: any, propertyKey?: string | symbol, | ||
propertyDescritorOrParameterIndex?: TypedPropertyDescriptor<BoundValue> | number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
- propertyDescritorOrParameterIndex
+ propertyDescriptorOrParameterIndex
} else { | ||
if (isPromise(inst)) { | ||
// Inject the properties asynchrounously | ||
return inst.then(obj => Object.assign(obj, propertiesOrPromise)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsistent with L39. Why is return obj
needed on L39 but not needed here?
Similarly for L43, why is return inst
needed?
} | ||
} | ||
|
||
const t = await instantiateClass(TestClass, ctx) as TestClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On L123 below, you have the following code:
const t = await instantiateClass(TestClass, ctx);
Can we use the same approach here and avoid the extra as TestClass
cast?
Please review other tests calling await instantiateClass
too and make the code consistent.
245311d
to
ee5056e
Compare
@bajtos Fixed. PTAL. |
ee5056e
to
87bbdb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Please rebase the patch on top of the current master. Among other things, it will enable Coveralls to verify that test coverage of the code has not decreased.
87bbdb3
to
fa17d60
Compare
cc @bajtos @ritch @superkhau