What is the proper way to update multiple properties from a ReactiveCommand?

70 views
Skip to first unread message

Atle

unread,
Mar 4, 2015, 2:17:48 AM3/4/15
to reacti...@googlegroups.com
Hi,

I have this command:
CreateSeries = ReactiveCommand.CreateAsyncTask(async _ =>
{
 var someInput = MayChangeWhileThisIsRunningProperty;

 string title = CreateTitle(someInput);
 var data = await GetDataAsync(someInput); <-- must create this here and not in the subscription since the property may change

 List<IChartSeriesViewModel> chartViewModels = CreateViewModels(data);
 return Tuple.Create(chartViewModels , title);
}

Then the result of this should update a bunch of properties:

_series = CreateSeries.ObserveOn(RxApp.MainThreadScheduler)
                                 .Select(x => new ObservableCollection<IChartSeriesViewModel>(x.Item1))
                                 .ToProperty(this, x => x.SeriesCollection);
_yRange = CreateSeries.ObserveOn(RxApp.MainThreadScheduler)
                                   .Select(x => CalculateYRange(x.Item1))
                                   .ToProperty(this, x => x.YRange);
_title = CreateSeries.Select(x => x.Item2)
                              .ObserveOn(RxApp.MainThreadScheduler)
                              .ToProperty(this, x => x.Title);

However, this feels a bit ineffective adding 3 subscriptions to a single command's results. Should all these be set at the bottom of the command's expression instead of returning the view models and the plot title?

- Atle

paul....@gmail.com

unread,
Mar 9, 2015, 1:45:49 AM3/9/15
to reacti...@googlegroups.com, reacti...@googlegroups.com
Hey Atle,

Nope, that looks fine to me. You don’t need the ObserveOns though.

Best,
Paul



--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages