Skip to content

Instantly share code, notes, and snippets.

@sdwvit
Last active November 23, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdwvit/eec96b9b31160ff1a0c828465a764093 to your computer and use it in GitHub Desktop.
Save sdwvit/eec96b9b31160ff1a0c828465a764093 to your computer and use it in GitHub Desktop.
Holy clean code
static checkComment(comment: Comment): void {
function resetCompactMode() { // TODO: props mutation is bad
comment.compactMode = false;
}
const parent = comment.compactMode && comment.parent;
if (!parent) { return; }
if (parent.level === 1 || parent.children.length > 1) {
resetCompactMode();
} else {
if (!parent.parent) { return; }
if (parent.parent.userId !== comment.userId || parent.parent.children.length > 1) {
resetCompactMode();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment