Skip to content

Instantly share code, notes, and snippets.

@conor909
Last active August 17, 2016 13:39
Show Gist options
  • Save conor909/3bcc763793252062e643c3fc8a27652f to your computer and use it in GitHub Desktop.
Save conor909/3bcc763793252062e643c3fc8a27652f to your computer and use it in GitHub Desktop.
declarative versus imperative
const minWidth = 220;
const minColumns = 1;
const maxColumns = 5;
const numberOfColumns = clamp(
this.props.containerWidth / minWidth,
minColumns,
maxColumns);
// vs
const { containerWidth } = this.props;
let numberOfColumns;
switch(true) {
      default:
      numberOfColumns = 5;
      break;
      case containerWidth < 640:
      numberOfColumns = 1;
      break;
      case containerWidth < 800:
      numberOfColumns = 2;
      break;
      case containerWidth < 900:
      numberOfColumns = 3;
      break;
      case containerWidth < 1050:
      numberOfColumns = 4;
      break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment