Skip to content

Commit

Permalink
Connections plugin now intercepts r.destroy()
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Nov 16, 2022
1 parent d5af1b9 commit 060cd36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<body>
<img id="hallstatt" src="640px-Hallstatt.jpg">

<button id="dbg">DEBUG</button>

<div id="content" class="plaintext">
<h1>Homer: The Odyssey</h1>
<p>
Expand Down Expand Up @@ -80,6 +82,10 @@ <h1>Homer: The Odyssey</h1>
});

r.loadAnnotations('annotations.w3c.json');

document.getElementById('dbg').addEventListener('click', function() {
r.destroy();
});
};
</script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions src/NetworkCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default class NetworkCanvas extends EventEmitter {
return toDelete.map(conn => conn.edge.toAnnotation());
}

destroy = () => {
this.svg.remove();
}

initGlobalEvents = () => {
const opts = {
capture: true,
Expand Down
8 changes: 7 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class ConnectionsPlugin extends EventEmitter {
*/
patchInstance = instance => {

// Intercept setAnnotation API method
// Intercept + monkeypatch API methods
const _setAnnotations = instance.setAnnotations;
const _destroy = instance.destroy;

instance.setAnnotations = arg => {
const all = (arg || []);
Expand All @@ -61,6 +62,11 @@ class ConnectionsPlugin extends EventEmitter {
});
}

instance.destroy = arg => {
this.canvas.destroy();
_destroy();
}

// When annotations are deleted, also delete
// in-/outgoing connections
instance.on('deleteAnnotation', annotation => {
Expand Down

0 comments on commit 060cd36

Please sign in to comment.