Is there a way to track when reactive command finished its execution?

☆樱花仙子☆ 提交于 2019-12-11 09:14:33

问题


Does anybody know how to track the fact that reactive command has finished its execution and hook up the method, which will start running after that?

P.S. The variant when calling the method in the end of the command's handler method does not fit in my situation.

Thanks in advance!


回答1:


ReactiveCommand has an observable property called IsExecuting that can be used to observe when the command is being executed. One way to handle this case would be doing something like this:

YourCommand.IsExecuting
    .Skip(1) // IsExecuting has an initial value of false.  We can skip that first value
    .Where(isExecuting => !isExecuting) // filter until the executing state becomes false
    .Subscribe(_ => YourMethodCall()); // run your method now that the command is done



回答2:


Eugene is totally right, but I wanted to mention an alternative option. If your command only returns one value (as most commands do), you can hook into the command itself is an observable that ticks the result of every successful execution:

YourCommand.Subscribe(result => YourMethodCall(result));

The advantage here is you now have access to the command's result in YourMethodCall.



来源:https://stackoverflow.com/questions/50177352/is-there-a-way-to-track-when-reactive-command-finished-its-execution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!