-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
createEntityAdapter with dynamic or fulfilled-order sortComparer #454
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
Comments
I can see in the source code for the unsorted adapter that insert-order is the default sort order. Would you consider documenting that and guaranteeing that it won't change without a breaking change version? |
Can you give an example of what you mean by "dynamic My main thought here is that the built-in sorting behavior is primarily a convenience factor. If you want something more complex or detailed, you should probably be managing your own sorting logic, in either reducers or selectors. There's a bit of a parallel with the techniques shown in the post Advanced Redux Entity Normalization, which talks about having multiple "keywindows", which are really just additional ID arrays with some specific subset of IDs in them. |
I'm trying to figure out exactly in what capacity should So, I was wondering if it was intended as a way to sort things on behalf of the user. I imagined that a "dynamic I don't think this is the true intention. I can see now that However, then I read the part about there being no guarantee of sort order if you don't supply a That seems like a lot of work to do when the default sort order of the unsorted entity adapter really is just insert-order (which would be the same as fetched-order for many of my use cases). So, the issue here really just ends up being a question of documentation - why not guarantee the default sort order of the "unsorted" entity adapter so that it's always by order of insertion? (Thanks for the link to the keywindows, I've certainly used that technique before. But when we're sorting on the server already - any additional work to re-sort things on the client would be undesirable.) |
@waynebloss Hey Wayne! In the usage guide documentation, we currently say:
To me, this implies that you get what you give (or an array behaves like an array?) if you don't specify a If this isn't clear enough, let me know and I'd be happy to open a PR with some ideas that bring more clarity to the docs. |
@msutkowski This is the confusing sentence, the last sentence in this section of the API reference:
Reading that was confusing to me because there was no positive statement about what the default sort order actually is. Instead, you have to infer it from a completely different documentation - the usage guide that you pointed out here |
I'll just go ahead and close this issue because it started out as me asking about the intended usage of the You can do whatever you want with your docs - I'm just trying to help you out by pointing out some confusion that I had. I'm sure most people will figure out the same thing on their own. I guess my problem was that I jumped straight to the API reference for these new features instead of re-reading the usage guide. |
Uh oh!
There was an error while loading. Please reload this page.
Can you give some guidance on how to do a dynamic
sortComparer
, e.g. ngrx/platform#898or if you would even want to do that?
The
sortComparer
defines the sort order for storage, so I'm not sure that having a dynamic sort for that purpose is a good idea. The first answer on the linked ngrx issue recommends just using a selector to sort, which is probably what I'd do instead of constantly changing the storage sort order.However, for the default order - I'd prefer it to be fulfilled-order (insert-order). Since you make no guarantees about the default ordering when no
sortComparer
is provided - how can I provide asortComparer
that always sorts the entities based on the order that they were fetched / fulfilled / inserted into the Entity Adapter?The text was updated successfully, but these errors were encountered: