jsxgraph.js: Best way to kill all event listeners

When we jump from one jsxgraph sketch to another, some processes continuous to work in the background. I would like to know what is the best way of kill all event listeners in jsxgraph.js. For example, in the case of "update hooks" we can use the JXG.Board method removeHook(). But this method is deprecated in favor of JXG.Board.off(). On the other hand, the methods JXG.Board.off() and JXG.Board.on() do not have any documentation.

Anyway, my question is how can I kill all running eventHandlers and processes associated with a given board, before a jump to the next sketch.

Thanks!

Upvotes: 0

Views: 139

Answers (1)

Alfred Wassermann
Alfred Wassermann

Reputation: 2323

The documentation for JXG.Board.on() and JXG.Board.off() is at https://jsxgraph.org/docs/symbols/JXG.EventEmitter.html.

The recommended way to get rid of all event listeners is to call JXG.JSXGraph.freeBoard(board) and init a new board.

In order to only remove all event listeners on JSXGraph elements and on the board itself - without removing the board - a cumbersome way (like in general JavaScript code) is to call off in the same way as the on method for all event listeners.

A very hacker-like method would be to set

JXG.EventEmitter.eventHandlers = {};

This should remove all event listeners on JSXGraph elements on the whole HTML page.

Upvotes: 0

Related Questions