-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Selecting one entity by id with adapters #1156
Comments
* add a new selector 'selectById' to EntitySelector (model) * implement selector, function to take id string || number * add tests See: ngrx#1156
Hey @mauriziocescon, really like that idea. I have implemented this selector over and over again for several entities/projects. |
#1152 is related to this issue. |
I think with the introduction of createselector with props and ngrx 6.1 (I think #1175 ), this issue can be closed: it seems to me it is working fine!
|
Here is the demo above with the new functionalities Great job, thanks! |
Ok, I'm glad you like it 😄 ; I'll close this issue and the according PR. |
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
What is the current behavior?
The entity adapter is great for managing a list of ng-components of the same type (like a list of users). Currently you can get some nice selectors out of the box:
Unfortunately, I very often need to select just one entity by its id (that never changes). A naive implementation of this requirement would be:
But in this case
this.user$
is updated every time anything changes in any entity (not only the one I'm interested in). Ifthis.user$
is passed using async pipe, this implies a useless refreshing of the ui in all user-dummy-components.Describe any alternatives/workarounds you're currently using
The solution (at least in my case) is to use something like this:
This way the selector is correctly memoized. I think it would be very helpful to have something ready out the box that devs can use to avoid writing the same code over and over.
Other information:
This is a simple demo that illustrates the two behaviors described above.
ngrx-adapter-multi-comp
If accepted, I would be willing to submit a PR for this feature
[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: