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

fix(emotion-utils): refactor position function #83

Closed

Conversation

yoonminsang
Copy link
Contributor

Overview

  • improve type safe
  • change wrong variable name

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

@netlify
Copy link

netlify bot commented Oct 23, 2022

Deploy Preview for slash-libraries ready!

Name Link
🔨 Latest commit 57aadbd
🔍 Latest deploy log https://app.netlify.com/sites/slash-libraries/deploys/63556c5123c4c20008203c72
😎 Deploy Preview https://deploy-preview-83--slash-libraries.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@hoseungme hoseungme changed the title <fix>[emotion-utils]: refactor position function fix(emotion-utils): refactor position function Oct 23, 2022
Comment on lines -74 to +86
topOrCoordinates: CSSPixelValue | Coordinates = {},
topOrRightOrCoordinates: CSSPixelValue | Coordinates = {},
...values: CSSPixelValue[]
) {
const [top, right, bottom, left] = isPositionValue(positionOrTop)
? isCSSPixelValue(topOrCoordinates)
? [topOrCoordinates, ...values]
: [topOrCoordinates?.top, topOrCoordinates?.right, topOrCoordinates?.bottom, topOrCoordinates?.left]
: [positionOrTop, topOrCoordinates as CSSPixelValue, ...values];
? isCSSPixelValue(topOrRightOrCoordinates)
? [topOrRightOrCoordinates, ...values]
: [
topOrRightOrCoordinates.top,
topOrRightOrCoordinates.right,
topOrRightOrCoordinates.bottom,
topOrRightOrCoordinates.left,
]
: [positionOrTop, topOrRightOrCoordinates as CSSPixelValue, ...values];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look just renaming. I think it's far from refactoring.
How about making the code more intuitive? (e.g. using IIFE to group related codes, or adding some comments to note what this code means, etc.)

@hoseungme
Copy link
Contributor

hoseungme commented Oct 24, 2022

Note my comment please. Thank you @yoonminsang !

@hoseungme hoseungme closed this Oct 24, 2022
@yoonminsang
Copy link
Contributor Author

Thanks for comments @hoseungjang

  • rename

I think renaming is refactoring.
I am studying refactoring with refactoring2 book(Martin Fowler). The book say naming is important. I attach my github link.
my github repo link

First I read this code, topOrCoordinates means top or Coordinates. But it means top or right or Coordinates. So I think this naming is wrong. If topOrRightOrCoordinates is so long, I rewrite something.

  • IIFE

I think Nested Ternaries is poor readability. But it taste difference. I attach links.
nested-ternaries-are-great
nested-ternaries-are-bad

If you agree with nested ternaries are great, I will pull request this code.

  const [top, right, bottom, left] = (() => {
    if (!isPositionValue(positionOrTop)) {
      return [positionOrTop, topOrRightOrCoordinates as CSSPixelValue, ...values];
    }
    if (!isCSSPixelValue(topOrRightOrCoordinates)) {
      return [
        topOrRightOrCoordinates.top,
        topOrRightOrCoordinates.right,
        topOrRightOrCoordinates.bottom,
        topOrRightOrCoordinates.left,
      ];
    }
    return [topOrRightOrCoordinates, ...values];
  })();
  • Other commits
    I write 3 commits. You comment only one commit. Other commits is ok?

If you want a new pull request, I will pull request. Thank you.

@hoseungme
Copy link
Contributor

hoseungme commented Oct 24, 2022

I think renaming is refactoring.
I am studying refactoring with refactoring2 book(Martin Fowler). The book say naming is important. I attach my github link.

@yoonminsang Yes, you are absolutely right. Sometimes renaming would be main point to make a readable code.

But, in the case of this position function, I think just renaming topOrCoordinates to topOrRightOrCoordinates have no impact to make it more readable.

But your IIFE example is what I want. It would be more readable than those complex ternaries. Please apply it and reopen this PR. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants