feat: Allow plugins to declare an action invalid #963
Merged
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.
Closes #962
This adds support for an
isInvalid
method in boardgame.io plugins. Similar to the currentnoClient
plugin method, this allows the reducer to ask plugins if everything is OK or if the current event/move is invalid from their point of view. If one or more plugins returns a truthy value from itsisInvalid
method, the reducer will fall back to its initial state, analogous to what it does when a move returnsINVALID_MOVE
.Currently this is not in use but the intention would be to use it for the events plugin, following on from #957. It also allows for other custom use cases, like state validators.
Notes
isInvalid
should return a string if the action is invalid. This could be less strict if that seems desirable.The error returned to the client is of the form
If more than one plugin’s
isInvalid
method returns a string, we just error with the first of them, rather than reporting all of them.