Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a non-trivial map between collections in Reactive Extensions?
    primarykey
    data
    text
    <p>I would like to implement a <strong>map from selected objects</strong> to <strong>property entries</strong> in property editor. For example like in Visual Studio xaml editor.</p> <p>The target map is something like this (or maybe using ReactiveCollection from ReactiveUI?)</p> <pre class="lang-none prettyprint-override"><code> Selected objects Filled categories to display in PropertyEditor ------------------------- --------------------------------------- ObservableCollection&lt;obj&gt; -&gt; ObservableCollection&lt;Category&gt; </code></pre> <p>The map in plain English:</p> <ol> <li>Collect all unique property types from objects</li> <li>Group by category (e.g. Text, Layout)</li> <li>Add/Remove categories as necessary to reflect selected objects</li> <li>Add/Remove properties from existing categories as necessary</li> </ol> <p>The challenge is to have declarative/functional code without add/remove branches. (I do already have an imperative/event based code which is quite ugly and error prone.)</p> <p>I think we could assume that Category and Property collections are sets with the usual operations: Union, Substract, and IsMember.</p> <p>The inspiration is the code from <a href="http://www.reactiveui.net/" rel="nofollow">ReactiveUI</a> by Paul Betts which is beatiful for simple one-to-one map:</p> <pre class="lang-cs prettyprint-override"><code>var Models = new ReactiveCollection&lt;ModelClass&gt;(); var ViewModels = Models.CreateDerivedCollection(x =&gt; new ViewModelForModelClass(x)); // Now, adding / removing Models means we // automatically have a corresponding ViewModel Models.Add(new Model(”Hello!”)); ViewModels.Count(); &gt;&gt;&gt; 1 </code></pre> <p>Using Seq and F# the straightforward nonobservable map would look like this:</p> <pre class="lang-ml prettyprint-override"><code>selectedObjects |&gt; Seq.collect GetProperties |&gt; Seq.unique |&gt; Seq.groupBy GetPropertyCategory |&gt; Seq.map (fun categoryName properies -&gt; CreateCategory(properties)) </code></pre> <p>The above code is fine in theory but in practice it would recreate all the view models from scratch on each change in selected objects. What I would love to achieve with Rex is to have the version of the above map <strong>with incremental updates</strong>, so the WPF will update only the changed parts of the GUI.</p>
    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. 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