If ou switchs (v3)

Revision 3 of this benchmark created on


Description

Verificar o que vai ter uma performance mais interessante

Test runner

Ready to run.

Testing in
TestOps/sec
usando apenas ifs
function handleApprovalStatus(status, current_step, postRegistrationUnderAnalysis, published) {
    if (status !== "approved") return;
    if (current_step === "board_registration_number") {
      navigate("/saude/verificacao-inscricao");
    } else if (current_step === "add_intersectionality_data" && !isDiversityRoute()) {
      navigate("/saude/diversidade");
    } else if (current_step && postRegistrationUnderAnalysis && isUnderAnalysisNotAllowedRoute()) {
      navigate("/saude/painel-inicial");
    } else if (!current_step && !published && !isNotActiveAccountAllowedRoute()) {
      navigate("/saude/painel-inicial");
    }
  }
ready
Usando switch
function handleApprovalStatus(status, current_step, postRegistrationUnderAnalysis, published) {
  // Se o status não for aprovado
  if (status !== "approved") {
    return;
  }

  // salvar os resultados das funções chamadas pra gastar menos requisições
  const isDiversity = isDiversityRoute();
  const isUnderAnalysisNotAllowed = isUnderAnalysisNotAllowedRoute();
  const isNotActiveAccountAllowed = isNotActiveAccountAllowedRoute();

  // O switch acho que atende melhor a validação do current_step
  switch (current_step) {
    case "board_registration_number":
      navigate("/saude/verificacao-inscricao");
      break;
    case "add_intersectionality_data":
      if (!isDiversity) {
        navigate("/saude/diversidade");
      }
      break;
    default:
      if (current_step && postRegistrationUnderAnalysis && isUnderAnalysisNotAllowed) {
        navigate("/saude/painel-inicial");
      } else if (!current_step && !published && !isNotActiveAccountAllowed) {
        navigate("/saude/painel-inicial");
      }
      break;
  }
}
ready
switch pattern matching
function handleApprovalStatus(status, current_step, postRegistrationUnderAnalysis, published) {
  // Se o status não for aprovado
  if (status !== "approved") {
    return;
  }

  // salvar os resultados das funções chamadas pra gastar menos requisições

  // O switch acho que atende melhor a validação do current_step
  switch (true) {
    case current_step === "board_registration_number":
      navigate("/saude/verificacao-inscricao");
      break;
    case current_step === "add_intersectionality_data" && isDiversityRoute():
      navigate("/saude/diversidade");
      break;
     case (current_step && postRegistrationUnderAnalysis && isUnderAnalysisNotAllowedRoute()):
     case !current_step && !published && !isNotActiveAccountAllowedRoute():
        navigate("/saude/painel-inicial");
      break;
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.