-
Notifications
You must be signed in to change notification settings - Fork 71
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
Rewrite InitialIcon
computation without mutable variables
#1186
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: ShatilKhan <[email protected]>
@BSFishy |
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.
@ShatilKhan This definitely looks like it's on the right track. You can probably take it further by moving the function outside the current scope, so you can write independent unit tests for it (one of the benefits of refactoring from mutable variables to a pure utility fn).
let initialIcon; | ||
let isLoading = false; |
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.
These should be removed now, right?
@@ -625,21 +625,27 @@ export class OuiIcon extends PureComponent<OuiIconProps, State> { | |||
let initialIcon; | |||
let isLoading = false; | |||
|
|||
// Category 1: cached oui icons | |||
// Define helper function | |||
const getIconAndLoadingStatus = (type: any) => { |
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 think we should already have a type for type
that's more narrow?
InitialIcon
computation without mutable variables
Signed-off-by: Shahriar Shatil <[email protected]>
Description
I have tried to use a helper function
getIconAndLoadingStatus
to return necessary values without having to mutate any variables.The returned values are then destructured into initialIcon and isLoading, which are used to set the state.Issues Resolved
Fixes #1167
Check List
yarn lint
yarn test-unit
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.