I want to get the latest value of the IdStream
and use it in command Execute
action.
public IObservable<Option<Guid>> IdStream { get; }
IdStream = documentStream.OfType<DocumentOpened().Select(x => x.Document.Id.Some())
.Merge(documentStream.OfType<DocumentClosed().Select(x => Option<Guid>.None()));
var saveCommand = ReactiveCommand.Create(() => Save(id), CanExecute);
I had tried to use the answer https://stackoverflow.com/a/31168822/7779560 and got something like this:
var saveCommand = ReactiveCommand.Create(() => { }, CanExecute);
saveCommand.WithLatestFrom(IdStream, (_, id) => id)
.Subscribe(id => Save(id));
And it works, but I can't use IsExecuting and ThrownExceptions command's functionality in this case (they act only for empty action which I passed as Execute during command creation).
UPD:
Execution order:
IdStream
creating- Command creating
documentStream
processesDocumentOpened
event (get some Id value - I checked it)saveCommand
execution
How can I achieve it?
UPD 2: I need also to await methods inside command body (SaveAsync
, for example).