-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(context): improve @inject.setter and add @inject.binding #2657
Conversation
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.
Personally, I prefer UNIX philosophy - many small tools where each tool does one job and does it well. In that light, I would prefer a new decorator for injecting the entire Binding
instance. You have mentioned @inject.binding
yourself in one of the earlier pull requests, what was the reasoning for your decision to put this new feature into the existing @inject.setter
function?
packages/authentication/src/__tests__/unit/providers/authentication.provider.unit.ts
Outdated
Show resolved
Hide resolved
packages/context/src/__tests__/acceptance/class-level-bindings.acceptance.ts
Outdated
Show resolved
Hide resolved
f4deea3
to
dcabfcd
Compare
I'm open here but I would like to avoid a new
If we decide to introduce |
64b81fb
to
76dc737
Compare
@bajtos I went ahead to add |
76dc737
to
623cf16
Compare
Awesome 👍 Here is my point of view:
With In that sense, |
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.
The new version looks good at high level, let's improve implementation details now.
The documentation changes in Decorators_inject.md
could use some extra attention to ensure consistency.
packages/context/src/inject.ts
Outdated
/** | ||
* Set the underlying binding to a const value. Returns the `Binding` object | ||
* so that the binding can be further configured, such as setting it to a | ||
* class with `toClass()`. |
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 find it weird to have two tsdoc comments for the same type. Which comment is rendered by our API docs? Can we keep only the comment that's picked up by our docs, and remove the other one please?
docs/site/Decorators_inject.md
Outdated
* be changed and returned as-is. | ||
*/ | ||
(value?: T) => void; | ||
``` |
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.
The implementation is using type Setter<T>
, please update this part of the docs to do the same.
u => (currentUser = u), | ||
u => { | ||
currentUser = u; | ||
return new Binding('authentication.currentUser').to(currentUser); |
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 don't see why is this change needed as there don't seem to be any tests depending on this new behavior. What's your intention here? Can we revert changes in this file?
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.
It's a mock-up return a binding object.
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.
Sure, I understand that, but I don't see any test in this file that would use that binding object. What's the point of creating & returning it then?
623cf16
to
9da57f1
Compare
@raymondfeng I don't have bandwidth to review this patch today, but I do want to check your updates before this patch is merged. Please give me few more days. |
u => (currentUser = u), | ||
u => { | ||
currentUser = u; | ||
return new Binding('authentication.currentUser').to(currentUser); |
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.
Sure, I understand that, but I don't see any test in this file that would use that binding object. What's the point of creating & returning it then?
2e40798
to
9be64e0
Compare
9be64e0
to
c7173e2
Compare
@bajtos PTAL |
@bajtos Ping. |
This option is configured at DI/IoC level in |
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.
👏
1. The decorators now allow binding creation policy control 2. `@inject.binding` can be used to resolve/configure a binding
c7173e2
to
8c29301
Compare
Extracted from #2635
@inject.setter
to set other forms of value providers than constantbindingCreation
option to control how the underlying binding is resolved/created.Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated