APIs to create cancellation commands for AsyncRelayCommand types #118
Labels
feature request 📬
A request for new changes to improve functionality
mvvm-toolkit 🧰
Issues/PRs for the MVVM Toolkit
open discussion ☎️
An issue open for active community discussion
Projects
Overview and motivation
The MVVM Toolkit has the
AsyncRelayCommandandAsyncRelayCommand<T>types, which make it easy to work with asynchronous operations through the usualICommandpattern, while also adding support for cancellation, progress report, etc. They have one limitation though, which is that it's not easy to define a command to cancel another command. Suppose you had this:This works fine. But now suppose you wanted to also have a button to cancel that operation. You'd need this:
This works, but it's (1) not portable (eg. doesn't work if the framework doesn't allow binding to methods), and (2) it doesn't follow the same usual command pattern: we're binding an event directly to a method in the viewmodel. It would be nice to have a way to create a command to handle this, but this requires a rather clunky setup today, as you need to create a command wrapping the other one, and also subscribe to
PropertyChangedon the first command, monitor forCanBeCanceledchanging and then update the second command from there. It's not really user friendly and also quite error prone, plus it could be optimized if supported internally.API proposal
We could add an extension like this:
This could then be used as follows:
We could then also add some way to automatically create a cancel command through source generators, like:
Which would generate the pair of command and cancel command.
Thoughts? Other API ideas or alternatives? 😄
cc. @michael-hawker @Arlodotexe
The text was updated successfully, but these errors were encountered: