ReactiveList.AddRange not working for large collections

413 views Asked by At

I have a simple TableView that displays a list of strings downloaded from the network. The list is very large (~140k strings). Using AddRange and nothing is happening, but if I statically code a small 2-item list, it works fine.

Code for reload command in view model:

        public ReactiveCommand<List<string>> LoadItems { get; protected set; }

        // Later, in the constructor...

        LoadItems = ReactiveCommand.CreateAsyncObservable(_ => BlobCache.LocalMachine.GetAndFetchLatest(
            client.ItemListKey,
            client.FetchItemList));

        LoadItems.Subscribe(list => {
            ItemList.Clear();
            ItemList.AddRange(list);
        }); 

If I change it to something like this, though, it actually adds cells to the table view:

        LoadItems.Subscribe(list => {
            Console.WriteLine(list.Count); // To see if it's working (it is)
            var stuff = new List<string>() {
                "Test item!"
            };
            ItemList.AddRange(stuff);
        }); 

My guess is that I'm adding the items in a very inefficient way and it's just not returning from the AddRange call. I'm VERY new to Rx/ReactiveUI/MVVM/all-this-cool-linq-stuff, but the premise is pretty awesome.

For what it's worth - I'm trying to do this on MonoTouch.

3

There are 3 answers

0
Cory Juhlin On BEST ANSWER

Looks like this issue was fixed in ReactiveUI 6.2.1.

0
Mongkon Eiadon On

I do like this try to checked.!

var search = this.ObservableForProperty(x => x.SearchQuery, _ => _)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .DistinctUntilChanged()
            .Select(q => Observable.Start(() =>
            {
                var searchResult = getSearchQuery(q);
                return searchResult;
            }).ObserveOn(SynchronizationContext.Current))
            .Switch()
            .Select(x => new ReactiveList<IProduct>(x.Result))
            .ToProperty(this, x => x.SearchResultList, out _SearchResultList);

and my function is

public async Task<IEnumerable<IProduct>> getSearchQuery(string query)
    {
        var service = new ProductService();
        var result = await service.SearchProductAsync(query);
        return result;
    }
0
Ana Betts On

I believe that this is a bug. Can you file an issue on the GitHub repo? (https://github.com/reactiveui/ReactiveUI/issues)