Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ShatilKhan
Copy link
Contributor

@ShatilKhan ShatilKhan commented Dec 15, 2023

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

  • New functionality includes testing.
  • New functionality has been documented.
  • All tests pass
    • yarn lint
    • yarn test-unit
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: ShatilKhan <shatilshahriar009@gmail.com>
@ShatilKhan
Copy link
Contributor Author

@BSFishy
Can you let me know if this is the right approach?

Copy link
Member

@joshuarrrr joshuarrrr left a 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).

Comment on lines 625 to 626
let initialIcon;
let isLoading = false;
Copy link
Member

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) => {
Copy link
Member

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?

@ShatilKhan ShatilKhan changed the title icon computation without mutable variables Rewrite InitialIcon computation without mutable variables Dec 16, 2023
ShatilKhan and others added 2 commits December 16, 2023 12:05
Signed-off-by: Shahriar Shatil <52494840+ShatilKhan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite initial icon computation without mutable variables
2 participants