Replies: 2 comments 1 reply
-
It's taking 4 seconds for the entire load process, or just for the filtering? If this includes processing for the View layer, 4 seconds for 65k does not sound crazy to me. UI layers are generally VERY slow, and WPF and all of its cousins are no exception. Even if you're not actually drawing UI for all 65k elements (which you're absolutely not doing in 4 seconds), you're still probably binding all 65k elements up to the UI, which means the UI is creating objects for them in the background, since I don't see any virtualization here. Although, to be fair, I'm very unfamiliar with the I.E. if 4 seconds is what you're observing with your eyeballs on the screen, that's probably not something you're doing wrong. If that's something you're measuring across some sub-portion of the RX stream, particularly if it's not touching the UI, there probably is something you're doing wrong.
I'm confused based on just the context being given here. What I see that immediately looks like the problem is that you have On a more general note, my approach to something like this would look pretty similar to what you have, but a little more RX-ified... _loadCommand = ReactiveCommand.Create(...);
_itemsSource = new SourceCache<...>(...);
_items = new ObservableCollectionExtended<...>();
this.WhenActivated(disposal =>
{
_loadCommand
.Do(_ =>
{
SearchCriteria = null;
Error = null;
})
.ObserveOn(RxApp.ThreadpoolScheduler)
.Select(_ => Observable.FromAsync(GetItemsAsync))
.Switch()
.Subscribe(items =>
{
using var suspension = _itemsSource.SuspendNotifications();
_itemsSource.Clear();
_itemsSource.AddOrUpdate(items);
})
.DisposeWith(disposal);
_itemsSource
.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Do(_ => IsLoading = true)
.ObserveOn(RxApp.ThreadpoolScheduler)
.Filter(this.WhenAnyValue(x => x.SearchCriteria)
.Throttle(TimeSpan.FromMilliseconds(500))
.DistinctUntilChanged()
.Select(Filter))
.TransformToTree(x => x.ParentOrganizationId)
.Transform(node => new OrganizationViewModel(node))
.ObserveOn(RxApp.MainThreadScheduler)
.DisposeMany()
.SortAndBind(_items, SortExpressionComparer<OrganizationViewModel>.Ascending(x => x.OrganizationName))
.Subscribe(_ => IsLoading = true)
.DisposeWith(disposal);
}); |
Beta Was this translation helpful? Give feedback.
-
I wouldn't say this. I'd say you just need to be smarter about how much you're pushing to the UI. Unfortunately, like I mentioned before, I don't have any familiarity with
I've not actually used Reactive UI a whole lot, believe it or not, so I don't know what all overloads there are for initializing a command. Me, I just rather like the idea of keeping all the real "logic" inside stream flows, so an "empty" command that just gets subscribed to to generate side-effects makes sense to me. You could maybe just move that first
Probably worth googling for "RX error handling" or similar and reading up on it, there's nothing special about errors with DD or with RX UI, but the gist is as follows: Normal RX notifications are published via .Select(_ => Observable.FromAsync(GetItemsAsync))
.Switch()
.Catch(error =>
{
// Display error popup to the user?
IsLoading = false;
return Observable.Empty<...>();
}) |
Beta Was this translation helpful? Give feedback.
-
I'm building a searchable tree data grid in avalonia using reactive ui + dynamic data. So far, I came up with the following solution:
First, I created a
LoadCommand
responsible for loading and refreshing the data:The
Load
method handles updating properties likeIsLoading
and setting theSourceCache
:Then I built a filter and bound it to the source like so:
And when view is activated, I execute the
LoadCommand
to load the data:This solution works ok, but there are some problems I'd like to resolve.
Isloading = true
, and hide it once the filtering completes. I attempted the following approach:However, the splash screen is hidden before the
LoadCommand
finishes. What’s the correct approach to ensure the splash screen is displayed throughout the entire filtering process?Beta Was this translation helpful? Give feedback.
All reactions