ealush / emoji-picker-react

The most popular React Emoji Picker
https://ealush.com/emoji-picker-react/
MIT License
1.04k stars 171 forks source link

Refactor - tennary operation should not be nested. #341

Closed ErezBiren closed 1 year ago

ErezBiren commented 1 year ago

Would be more clear to use another line to express the nested operation as a separate statement.

export function queryScrollBody(root: NullableElement): NullableElement {
  return root
    ? root.matches(asSelectors(ClassNames.scrollBody))
      ? root
      : root.querySelector(asSelectors(ClassNames.scrollBody))
    : null;
}

Maybe somethig like this.

export function queryScrollBody(root: NullableElement): NullableElement {
  if (!root) return null;

  return root.matches(asSelectors(ClassNames.scrollBody))
    ? root
    : root.querySelector(asSelectors(ClassNames.scrollBody));
}

If you want I can PR it.

ealush commented 1 year ago

I agree. Brevity is not a good enough excuse. I wrote the entire codebase in a month or two, so I just did it the way it was fastest to me at that moment.

I think your proposal is more readable.