-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
[Feature]: Bind operation with Sorting #837
Comments
I'm going to share some of my experiences with Sorting because I do it very often. A lot of this is probably irrelevant to this issue, but I'm adding it because it is loosely related. Sorry for the wall of text. In many of my ViewModels, I have an API that returns a list of elements to be displayed in the UI. It is almost boilerplate for me to make a ViewModel with a I then bind the So, I often bind to the list with something like this:
There are two common cases in which I have to deviate from this pattern:
In case #1, I'd love it if something like a sorted In case #2, I don't think anything can be done here. I'm not sure if it's worth creating a separate issue or if that's intended behavior. EDIT: Maybe if there were a |
@timothylcooke The reason Dynamic Data only supports ObservableCollectionExtended and ReadonlyObservableCollection is historic when I wanted Dynamic Data to be optimal out of the box, otherwise I feared no-one would ever take it seriously. In the case of binding, the restriction for using ObservableCollectionExtended is that it is much more optimal to fire a Reset when there are a large number of changes, so code enforces that. With the standard observable collection and with arbitrary lists this is not possible. That said I think the global community is well trained enough to automatically use the fast version, even if we were to introduce additional bind methods. Therefore I'd agree that BindToList would be a good addition to the lib.
You're right, this is a tricky scenario. The nature of the the cache side of DD is that it does not maintain order as it stores state via keys only. However what may be worth trying is to convert it to a list first: mySourceCache
.RemoveKey() // Makes it an observable list which does maintain order (mostly but not for dynamic filtering)
.Sort(SortExpressionComparer<MyRecordType>.Ascending(x => x.OrderBy))
.Transform(x => new MoreComplexType(x))
.Bind(out var mySortedList)
.Subscribe(); |
@RolandPheasant As always, thanks for the great feedback. I'm excited to try out For the purposes of this issue, none of my above feedback is relevant unless you decide to:
FWIW, I'm in no way married to the |
@timothylcooke Since @RolandPheasant likes your idea for a new operator, then I think you should open a new issue for it so someone will work on it. Better yet, you could follow it up with a PR since you already have an implementation. All you'll need is some unit tests. I would suggest a slightly different prototype for it though: public static IObservable<IChangeSet<TObject, TKey>> Bind<TObject, TKey>(this IObservable<IChangeSet<TObject, TKey>> source, out IReadOnlyList<TObject> list); You don't want something outside of the operator to be able to change the list because it would break the Indexing. Would it work for your scenario if the list were |
No, It would have to be |
I wonder whether we could introduce an analyser which warms about the dangers of binding to an amendable list. The consumer can turn it off, but at least they know. |
There's probably a variety of usage suggestions we could give, through an analyzer. I believe it can be bundled into the package as a dev-only dependency as well. |
@timothylcooke #878 is my proposed solution, which also binds to IList but of course it will also need a non-sorted bind which can handle iList too. |
@RolandPheasant Definitely looks great! I'm excited to try it out. It really feels like this is the way to handle this. So, for the times when I'm forced by some pesky control to use an Are you planning on making an equivalent operator on Do you plan on adding any sort of analyzers to suggest not using the IList overload? |
@timothylcooke can you proof read this for me please https://github.com/reactivemarbles/DynamicData/wiki/Sort-And-Bind-Operator As well as my points in the wiki I should also include a bind overload that accepts and arbitrary instance of iList from the cache side, and probably rename |
SortAndBind has been release in v8.4.1 |
Looks great. I made some tiny fixes, but all-in-all, I think it's very clear and easy to follow. Good work. |
Thanks @timothylcooke. I am working on a version of SortAndBind which accepts an observable of comparers, meaning sort can be switched. When that's done, the new bind and sort will have functional parity with the prior version. |
@RolandPheasant I went through one of my projects yesterday and changed a lot of my
|
That's great to hear. If you have any issues I'll get on the case asap.
Regarding combing operators, I think it is generally a good idea. For example, I always transform a grouping immediately after creating a group. So surely better to have an overload on group that takes a transform. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Describe the functionality desired
A new Bind operator that takes a sort comparer that is applied to the resulting collection.
From @RolandPheasant on Slack:
The steps the functionality will provide
The ability to have a sorted ObservableCollection without having to apply a Sort operator explicitly which is more expensive.
Considerations
Using Sort followed by Bind works, but it would be more performant to have in a single step because it would do away with an intermediate changeset.
The text was updated successfully, but these errors were encountered: