-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Prevent "impossible" state inside the store
I have noticed that in some places, the store uses a few variables to describe the state of the same thing (a request status). But the possible value combinations for these variables are not implicit, which could lead to impossible states in the long run, which are considerably difficult to debug.
My suggestion to prevent impossible states: map the possible states (maybe create an interface for each?) and add the types to the store. Or, to be more specific: instead of having multiple state variables (isProcessing, isSuccess, value, error) there could be only status ("processing" | "success" | "error") and value (either the success payload or the error message). That way we would get a compilation error every time we tried to assign an impossible state to the store (like isSuccess equal to true and a non-nullish value for error), preventing bugs and leading to a more predictable state.