Regarding recreating/reloading snapshot collections #491
Unanswered
AliveDevil
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So … I'm wondering whether this is the "optimal" way (or in general considered as the regular way of solving this).
I have a ViewModel which includes a ReactiveCommand returning a
IEnumerable<T>
, which is subscribed to in the WhenActivated-event for ReactiveUI (as ind(ViewModel.LoadCommand.Execute().Subscribe());
).Data comes from a EFCore DbContextFactory which is dependency injected into the ViewModel.
The LoadCommand is implemented as I'd say is just normal:
Without clearing the SourceList navigating out of the View and navigating back into it duplicates all entries.
Now to get my Model-class into a ViewModel I perform a
ToObservableChangeSet
-conversion, withNow there is PopulateInto, but somehow this doesn't look that appealing to me (as in: I'd rather have an Observable which automatically resets itself when a new List comes in). Using
BindTo(out BindingList)
doesn't work, as Clearing that will result inArgumentOutOfRange
exceptions, andReadOnlyObservableCollection
cannot be cleared.Getting the
SourceList<ChallengeViewModel>
into my view this is done perUsing a
ReadOnlyObservableCollection
is kinda inconvenient here, as it requires setting up a field which is then forwarded through a auto-init readonly property.Is there an easy way of getting a auto-reset
IObservable<IChangeSet<>>
for on-demand loadedIEnumerable
s? Ideally without requiring fields (I can assign a read-only property, or bind to a BindingList or similar) or temporary variables (as the SourceList above).The data flow should look like Command creates a new list everytime it is executed, that list is turned into a transformed ViewModel, sorted and bound to some output property, without using that intermediate SourceList.
For reference this is the complete code:
// Update:
I just checked something. With the SourceList as a resettable buffer PopulateInto wouldn't work well (as it's throwing exceptions left and right after being cleared).
Here is the ArgumentException for this specific case: System.ArgumentException.txt
Beta Was this translation helpful? Give feedback.
All reactions