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

130
Visualizações
Methods addDiagramListener and removeDiagramListener is never getting called in gojs

Hope you all are doing well!! I'm facing some issues in calling the Diagram event. Here I'm posting a few use-cases which didn't work for me and what's worked.

CASE I) Did not work : Calling addDiagramListener and removeDiagramListener one after other for the same function reference "setLayout" didn't work. None of them or both addDiagramListener or removeDiagramListener got fired.

export class DiagramListenerTestClass {
  execute(context: any): any {
    let diagram = context.diagram;
    diagram.layout = new go.ForceDirectedLayout;
    diagram.addDiagramListener("LayoutCompleted", setLayout);
    diagram.removeDiagramListener("LayoutCompleted", setLayout);
 }
}

// Define outside the class
var setLayout = function (event) {
  event.diagram.layout = new go.Layout();
  console.log("Method called!!");
}

CASE II) Worked : Calling removeDiagramListener after some setTimeout, fired both addDiagramListener and removeDiagramListener.

export class DiagramListenerTestClass {
  execute(context: any): any {
    let diagram = context.diagram;
    diagram.layout = new go.ForceDirectedLayout;
    diagram.addDiagramListener("LayoutCompleted", setLayout);
    setTimeout(() => { diagram.removeDiagramListener("LayoutCompleted", setLayout) }, 100);
 }
}
// Define outside the class
var setLayout = function (event) {
  event.diagram.layout = new go.Layout();
  console.log("Method called!!");
}

Note: I'm not sure about the reason why case II worked and not CASE I. What I assume for the successful execution of CASE II is that: "the calls for addDiagramListener and removeDiagramListener was so quick that before addDiagramListener 'setLayout' function gets called, the listener gets removed by 'removeDiagramListener' ".So to get's the function successfully executed, I called 'removeDiagramListener' with some setTimeout of 100ms.

Please do let me correct if there's something not correct. Your suggestions would be very helpful and appreciated!! Thanks in advance!!

about 4 years ago · Juan Pablo Isaza
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