Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda