Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a bit involved, but I'll try to explain it succinctly!</p> <p>The core idea is to start with a buffered stream of PropertyChangedEvents(PCE), but then switch to a new buffered stream every time there is a CollectionChangedEvent (CCE). Finally we merge the CCE and flattened buffered stream of PCE together.</p> <p>We start collectUpdateItems by converting the CCEs to a stream of <code>Unit.Default</code> and <code>StartWith</code> an initial value (this lets us start collecting PCEs before the first CCE). When then project (<code>Select</code>) each pulse into a new buffered stream of PCEs. The <code>Switch</code> will ensure only the most recent buffer stream is returned. The <code>Where</code> just drops empty buffers.</p> <p>Finally we <code>Merge</code> this with the original CCE stream (projected into single element lists for compatibility with the PCE buffers).</p> <p>Hope this makes sense!</p> <p>Modifying your streams slighty to start with plain, unbuffered ChangeDTO object streams:</p> <pre><code>IObservable&lt;IEnumerable&lt;ChangeDTO&gt;&gt; allItems = Observable.FromEventPattern&lt;CollectionChangedEventArgs&gt;( x =&gt; source.CollectionChanged += x, x =&gt; source.CollectionChanged-= x) .Select(i =&gt; new ChangeDTO(source.SelectedItems, true, null)}); IObservable&lt;IEnumerable&lt;ChangeDTO&gt;&gt; updatedItem = Observable.FromEventPattern&lt;PropertyChangedEventArgs&gt;( x =&gt; source.PropertyChanged += x, x =&gt; source.PropertyChanged -= x). .Select(i =&gt; new ChangeDTO(new[] {source.Item}, false, source.UpdatedProperties)); var collectUpdatedItems = allItems // We only need to know the CCE happened, not the details of it, so convert to Units .Select(_ =&gt; Unit.Default) // We must insert an event so PCEs are buffered before the first CCE .StartWith(Unit.Default) // Here we create a new PCE buffer stream at the start and after each CCE .Select(_ =&gt; updateItem.Buffer(TimeSpan.FromMilliseconds(300))) // On a CCE, switch to the new PCE buffer stream, dropping the current PCE buffer .Switch() // Finally drop any empty buffers .Where(i =&gt; i.Count &gt; 0); // merge the CollectionChangedEvents with the PropertyChangedEvent buffers return collectionUpdateItems.Merge(allItems.Select(i =&gt; new List&lt;ChangeDTO&gt; {i})); </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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