Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!