pavle-doby

good.js
function toShowLoader() {
  const isFetching = apiStore[apiCallName] === "fetching";
  const isAdmin = permissionStore.role === "admin";
  const isListEmpty = !topTierList.length;

  return isFetching && isAdmin && isListEmpty;
}

if (toShowLoader()) {
  showLoader();
}
bad.js
if (
  apiStore[apiCallName] === "fetching" &&                 
  permissionStore.role === "admin" &&  
  !topTierList.length
) {
  showLoader();
}
JavaScript logo

Encapsulate conditionals

Pavle Marinkovic