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

one-liner statement everywhere #235

Closed
the-liquid-metal opened this issue Oct 31, 2019 · 1 comment
Closed

one-liner statement everywhere #235

the-liquid-metal opened this issue Oct 31, 2019 · 1 comment

Comments

@the-liquid-metal
Copy link

the-liquid-metal commented Oct 31, 2019

one-liner statement is more attractive than multi-liner, and closer to jquery style.
also:

  • remove parentheses in closure param if possible in order to remove distraction.
  • convert function to bare statemant.
  • use ternary operator
  • more pragmatic example

All previous siblings (bare statemant):
[...el.parentNode.children].filter((item, idx, self) => idx < self.indexOf(el) && item.matches($selector))

All next siblings (bare statemant):
[...el.parentNode.children].filter((item, idx, self) => idx > self.indexOf(el) && item.matches($selector))

FadeToggle (ternary operator):
el.style.opacity = (opacity === "1") ? "0" : "1";

isEmptyObject (a pragmatic way):

// usage in IF statement
if (Object.keys(obj).length) {
    // ...
}

note: in most case isEmptyObject is used in IF statement. Object.keys returns array. array.length is always number. 0 is converted to false, otherwise true. there is no need to create function in order to replace isEmptyObject.

@camsong
Copy link
Owner

camsong commented Dec 12, 2019

Looks good, could you make a PR? You can add native one-liner style to part of the statement.

@camsong camsong closed this as completed May 23, 2021
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

No branches or pull requests

2 participants