Skip to content

Commit

Permalink
chore: remove redundant conditional expressions and consistently use …
Browse files Browse the repository at this point in the history
…!! (#1228)
  • Loading branch information
leyanlo authored and gergelyke committed May 2, 2019
1 parent 2c42188 commit d3414f1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {BABEL_ENV} = process.env;
const modules =
BABEL_ENV === 'es' || BABEL_ENV === 'modules' ? false : 'commonjs';
const modules = !(BABEL_ENV === 'es' || BABEL_ENV === 'modules') && 'commonjs';

module.exports = {
presets: [
Expand Down
2 changes: 1 addition & 1 deletion documentation-site/static/examples/modal/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ModalStateContainer extends React.Component {
};
toggle = (open = !this.state.isOpen) => {
this.setState({
isOpen: Boolean(open),
isOpen: !!open,
});
};
open = () => {
Expand Down
2 changes: 1 addition & 1 deletion jest-puppeteer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LICENSE file in the root directory of this source tree.
let headless = true;

if (process.env.PUPPETEER_HEADLESS) {
headless = process.env.PUPPETEER_HEADLESS === 'false' ? false : true;
headless = process.env.PUPPETEER_HEADLESS !== 'false';
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/button-group/button-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function ButtonGroupRoot(props: {|...PropsT, ...LocaleT|}) {
}

return React.cloneElement(child, {
disabled: props.disabled ? true : child.props.disabled,
disabled: props.disabled || child.props.disabled,
isSelected: isSelected(props.selected, index),
kind: KIND.tertiary,
onClick: event => {
Expand Down
2 changes: 1 addition & 1 deletion src/card/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import type {CardsPropsT} from './types.js';

export function hasThumbnail(props: {+thumbnail?: string}) {
return Boolean(props.thumbnail);
return !!props.thumbnail;
}

function Card(props: CardsPropsT) {
Expand Down
5 changes: 2 additions & 3 deletions src/datepicker/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ export default class Day extends React.Component<DayPropsT, DayStateT> {
const {date, value, highlightedDate, range, highlighted} = this.props;
const $isHighlighted = highlighted;
const $selected = this.isSelected();
const $hasRangeHighlighted =
const $hasRangeHighlighted = !!(
Array.isArray(value) &&
range &&
value.length === 1 &&
highlightedDate &&
!isSameDay(value[0], highlightedDate)
? true
: false;
);
return {
$date: date,
$disabled: this.props.disabled,
Expand Down
2 changes: 1 addition & 1 deletion src/modal/__tests__/modal.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ModalStateContainer extends React.Component<
};
toggle = (open?: boolean = !this.state.isOpen) => {
this.setState({
isOpen: Boolean(open),
isOpen: !!open,
});
};
open = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ class Modal extends React.Component<ModalPropsT, ModalStateT> {
return {
$animate: animate,
$isVisible: this.state.isVisible,
$isOpen: Boolean(isOpen),
$isOpen: !!isOpen,
$size: size,
$role: role,
$closeable: Boolean(closeable),
$closeable: !!closeable,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Popover extends React.Component<PopoverPropsT, PopoverPrivateStateT> {
const {isOpen, showArrow} = this.props;
const {isAnimating, arrowOffset, popoverOffset, placement} = this.state;
return {
$showArrow: Boolean(showArrow),
$showArrow: !!showArrow,
$arrowOffset: arrowOffset,
$popoverOffset: popoverOffset,
$placement: placement,
Expand Down
4 changes: 2 additions & 2 deletions src/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Select extends React.Component<PropsT, SelectStateT> {
if (this.input) this.input.value = '';

this.setState(prev => ({
isOpen: this.focusAfterClear ? false : !prev.isOpen,
isOpen: !this.focusAfterClear && !prev.isOpen,
isPseudoFocused: false,
}));

Expand Down Expand Up @@ -255,7 +255,7 @@ class Select extends React.Component<PropsT, SelectStateT> {

let toOpen = this.state.isOpen || this.openAfterFocus;
// if focus happens after clear values, don't open dropdown yet.
toOpen = this.focusAfterClear ? false : toOpen;
toOpen = !this.focusAfterClear && toOpen;

this.setState({
isFocused: true,
Expand Down
4 changes: 1 addition & 3 deletions src/side-navigation/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default class SideNav extends React.Component<NavPropsT> {
renderItem: null,
};

activePredicate = (item: Item) => {
return item.itemId === this.props.activeItemId ? true : false;
};
activePredicate = (item: Item) => item.itemId === this.props.activeItemId;

render() {
const {
Expand Down

0 comments on commit d3414f1

Please sign in to comment.