-
Notifications
You must be signed in to change notification settings - Fork 245
refactor(compass-global-writes): remove in-progress states #6475
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
Conversation
|
I think this is a really great refactor, but I'm wondering if we can be more ambitious in our refactor and just not represent |
| }, | ||
| (state: RootState) => ({ | ||
| namespace: state.namespace, | ||
| isSubmittingForSharding: state.userActionInProgress === 'submitForSharding', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use enums here instead of raw strings for safety, and to emphasize this is another kind of status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type safety is the same with union types. We tend to use union types in Compass, unless there is a reason to prefer enums - for example if the values are not very readable and we want to label them, or if we expect the values to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which makes me wonder why we used enum for ShardingStatuses 🤔
| pollingTimeout?: never; | ||
| loadingError: string; | ||
| ////////////// | ||
| userActionInProgress?: never; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move userActionInProgress to RootState and restrict as needed in the more specific actions. Also recommend using enum so that ShardingStatuses + UserActions form the complete state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the restriction. I had the full type in the root before, but then I removed it because it seemed unnecessary since each union part had a different definition. I can add it again for readability
| (state.status === ShardingStatuses.NOT_READY || | ||
| state.status === ShardingStatuses.SHARDING) | ||
| ) { | ||
| if (state.pollingTimeout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks OK, I guess I don't see why you would check for a timeout immediately after the request gave a response. Do you agree, and is that the reason you're removing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was happy to get rid of this part, I don't think this logic should be in the reducer, reducer is for translating action to new state. Previously I was kind of pushed to do this by the RootState types, but now the pollingTimeout is moved out of the RootState and is handled in the actions.
Yes, |
18d9d55 to
2462974
Compare
Description
Motivation:
As new flows have been added, the complexity of the reducer grew and seems difficult to grasp/maintain.
Changes:
userActionInProgressfromstatusstatus: UNMANAGING_NAMESPACE_MISMATCHnow becomesstatus: SHARD_KEY_MISMATCH; userActionInProgress: unmanageNamespacepollingTimeoutreference outside of theRootStateNew state diagram
Tests:
Acknowledgements
Big thanks to @Sergey Petushkov for brainstorming and ideas, I have a much better feeling about the reducer complexity now!
Checklist
Motivation and Context
Open Questions
Dependents
Types of changes