This repository was archived by the owner on May 1, 2024. It is now read-only.
Make parameters in CommandFactory class consistent #811
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
CommandFactory
that was merged in #797 is not quite one that is described in issue or PR description.When @brminnick separated
CommandFactory
into partial classes some changes to its API were made.This PR is intended to restore some of them.
Command
were changed to accept the same parameters thatCommand
constructors do which ruins the point of this class a little, since now some overloads ofCommandFactory.Create
accept different parameters from those that returnAsyncCommand
orAsyncValueCommand
. Main benefit of this class is that it can automatically switch betweenICommand
implementations basically based on whetherexecute
returnsvoid
orTask
(orValueTask
)execute
in all overloads for all commands, which reintroduces ambiguity between async commands if more then two parameters are specified.What was done:
CommandFactory.Create
forCommand
accept exactly the same parameters as overloads for async command do (exceptexecute
doesn't return task). This implementation of those overloads is different from ones that were in previous PR. Current behavior mimicsCammnd
behavior for type validation (do nothing ifexecute
type is not correct, and returnfalse
ifcanExecute
type is not correct) instead ofAsyncCommand
behaviour (throw exception if type id not correct).execute
parameter forAsyncCommand
toexecuteTask
andAsyncValueCommand
toexecuteValueTask
. This is helpful to resolve ambiguity between themCommandFactory.Create(executeTask: async () => {}, null, null)
canExecute
parameter forCreate<TExecute, TCanExecute>
mandatory. It doesn't make sense to specify type for a parameter and not provide it.Bugs Fixed
Behavioral Changes
CommandFactory.Create
accepts the same parameters for all command types (except async execute for commands returns tasks, and nothing for regular one).PR Checklist