Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] ReactiveCommand IsExecuting #276

Closed
michaelstonis opened this issue Nov 26, 2024 · 3 comments
Closed

[Suggestion] ReactiveCommand IsExecuting #276

michaelstonis opened this issue Nov 26, 2024 · 3 comments

Comments

@michaelstonis
Copy link
Contributor

It would be helpful if there were a way to track when a ReactiveCommand is executing. This can be helpful in many UI scenarios. For example, when a button click is bound to a command, you may want the button to remain disabled while execution is performed. I believe that ReactiveCommand<T> and ReactiveCommand<TInput,TOutput> could be extended to provide this by wrapping the execution or convert/Async, respectively.

Is this functionality that would be considered for R3?

Below is just a simple pseudo implementation of the concept. I am sure that there is a far more elegant way to approach this, but just wanted to put this here to show the functionality.


bool or IObservable<bool> IsExecuting;

public ReactiveCommand(Action<T> execute)
{
    this.list = new FreeListCore<Subscription>(this);
    this.canExecute = true;
    this.subscription = this.Subscribe(ManageExecution(execute));
}

private void ManageExecution(Action<T> execute)
{
	IsExecuting = true;
	execute();
	IsExecuting = false;
}
@neuecc
Copy link
Member

neuecc commented Dec 2, 2024

Thanks.
Since there don't seem to be any performance concerns, it looks like it would be worth implementing.

@michaelstonis
Copy link
Contributor Author

I added the following PR: #280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants