Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
How to reduce function call count for a function that is run after animation completion with Cytoscape

I have an animation on a collection of nodes. However, after completion of the animation I want it to call a function just once, but the function is apparently called as many times as there are nodes in the collection. Is there a way to stop this? I just want it to run once. Fairly new to Javascript, appreciate any help.

  collection.animate({
    style: {
      'line-color': 'red',
      'target-arrow-color': 'red',
      'border-width': 20,
      'border-color': 'red'
    }
  }, {
    'duration': 3000,
    'complete': () => "hello world";
  });

Prints 9x "hello world" since my collection of nodes and edges is of length 9 (subbranch of nodes & edges in a directed graph)

https://i.imgur.com/K3yyMv7.gif

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This should be easy. Just put a boolean variable to check if is already executed.

let isExecuted = false;

collection.animate({
  style: {
    'line-color': 'red',
    'target-arrow-color': 'red',
    'border-width': 20,
    'border-color': 'red'
  }
}, {
  'duration': 3000,
  'complete': () => {
    if (isExecuted) {
      return;
    }
    console.log("hello world");
    isExecuted = true;
  };
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda