ReactiveCommand.CreateFromTask vs ReactiveCommand.CreateFromObservable

I saw some discussions being discussed using Observables instead of tasks with async / await. I am currently using CreateFromTask almost exclusively. I am trying to understand the reasons for using CreateFromObservable instead of CreateFromTask.

And if so, what would be the best way to convert CreateFromTask to CreateFromObservable.

+5
source share
1 answer

CreateFromTask is really only present as an assistant, because we live mainly on the basis of tasks :-) In a completely reactive world, all the libraries that you use will simply open Observables. Then you can just be from end to end. But, seeing that this is not the case, RxUI includes some helpers who easily pull Tasks into Teams.

If you look here https://github.com/reactiveui/ReactiveUI/issues/1245

You will even see a discussion there just to get rid of these assistants.

if you look at the code for "CreateFromTask", all it does is call ToObservble () in the task to convert it to Observable, and then the code calls CreateFromObservable

https://github.com/reactiveui/ReactiveUI/blob/develop/src/ReactiveUI/ReactiveCommand.cs#L418

So, to this question, I would simply say that calling ToObservable in Task is the best way to convert it. You will need to include this using statement.

using System.Reactive.Threading.Tasks 

What I usually do is just wrap all my task-based libraries using the facade and expose them with ToObervable. If you come with reactive solutions, this will simply simplify the work on the Earth Observables, the opposite of mixing and matching.

The rationale behind CreateFromObservable over CreateFromTask is that the library assumes that your solution basically reacts in such a way that this will be the main way it will expect. All other ways to create these commands are really just helpers, which ultimately make the CreateFromObservable way

+4
source

Source: https://habr.com/ru/post/1264533/


All Articles