Skip to content

Simplify selected results table handling #169

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

Merged
merged 1 commit into from
Nov 19, 2019

Conversation

jcreedcmu
Copy link
Contributor

We don't need to render all tables and use css to hide the ones we
don't currently want to see. Instead have render return the dom that
should be visible given the current state.

We don't need to render all tables and use css to hide the ones we
don't currently want to see. Instead have `render` return the dom that
should be visible given the current state.
const toggleDiagnosticsClass = cx(toggleDiagnosticsClassName, {
[toggleDiagnosticsSelectedClassName]: selectedTable === ALERTS_TABLE_NAME
});
const diagnosticsCheckBox = selectedTable === ALERTS_TABLE_NAME ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use if instead of ternary so it's easier to read, since the assigned value here has a lot of text!

Copy link
Contributor Author

@jcreedcmu jcreedcmu Nov 19, 2019

Choose a reason for hiding this comment

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

I don't care for the fact that

  let val: SomeType | undefined = undefined;
  if (condition)
    val = someComputation();

requires a type annotation, and makes val mutable, when I know that for the rest of the function it should be const. Would you be ok with the idiom condition && someComputation() instead of the ternary, since at least in that case there isn't an undefined stranted after the someComputation()? (I didn't realize until I looked it up just now that react also renders false as nothing, just as it does undefined)

(A utility function renderIf<T>(condition: boolean, value: T): T | undefined could work, though it would have the undesirable consequence that value would be computed regardless of the condition, and

renderIf<T>(condition: boolean, computation: () => T): T | undefined {
  if (condition) return value(); else return undefined;
}

would of course solve that, but that would make you have to throw extra () => in every callsite)

Copy link
Contributor Author

@jcreedcmu jcreedcmu Nov 19, 2019

Choose a reason for hiding this comment

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

(@henrymercer agreed in an earlier conversation that it's unfortunate typescript lacks good concrete syntax for conditionals and switch statements as expressions :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sigh. The minor increase in readability is not worth any of these :) I do appreciate the thorough investigation of options.

@adityasharad adityasharad merged commit 4287f4d into github:master Nov 19, 2019
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.

2 participants