Note that there are some explanatory texts on larger screens.

plurals
  1. POFilling ObservableCollection through use of RX
    primarykey
    data
    text
    <p>I was wondering if following scenario could be fixed by using RX?</p> <p>I have a REST service call that has an input parameter distance and loads data, this data is than inserted in the ObservableCollection of the ViewModel so that the View will show the data... Pseudo code like this:</p> <pre><code>public async Task&lt;int&gt; LoadData(int distance) { this.ListOnUI.Clear(); var dataList = await Task.Run(() =&gt; _dataService.GetListAsync(distance)); foreach(var dataItem in dataList) { this.ListOnUI.Add(dataItem); } return dataList.Count; } </code></pre> <p>Now this small code snippet is wrapped inside a method, that returns the count of the dataList. What I do with that count, check if the amount returned is at least 20, if not I recall the method with a larger distance.</p> <p>So what is wrong with this setup...</p> <ol> <li>Each time the method is called the UI list is cleared</li> <li>The user sometimes has to wait long until we reach 20 items</li> <li>While we haven't reached 20 items, the UI will act weird with the clearing of the list</li> </ol> <p>So my gut feeling is telling me this could be solved by using RX somehow, so that we 'chunk' load/add the UI list.</p> <p>But my knowledge of RX is not good enough to solve it... so any ideas?</p> <p>REMARK: When we call the LoadData service we are getting a JSON string that is then mapped to a collection of DataItems, so if we not clear the UI ObservableCollection and would just Add them with each itteration... we would get the same item multiple times in the list because it are newly constructed objects ( although with the same data ).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload