Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Handle non-detach connection detach events
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm committed Apr 15, 2015
1 parent 01507b3 commit 09123c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
21 changes: 14 additions & 7 deletions go/base/static/js/src/components/plumbing/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@
},

onPlumbConnect: function(e) {
var sourceId = $(e.source).attr('data-uuid'),
targetId = $(e.target).attr('data-uuid'),
connectionId = idOfConnection(sourceId, targetId);
var sourceId = $(e.source).attr('data-uuid');
var targetId = $(e.target).attr('data-uuid');
var connectionId = idOfConnection(sourceId, targetId);

// Case 1:
// -------
Expand Down Expand Up @@ -176,19 +176,26 @@
},

onPlumbDisconnect: function(e) {
var sourceId = $(e.source).attr('data-uuid'),
targetId = $(e.target).attr('data-uuid'),
connectionId = idOfConnection(sourceId, targetId);
var sourceId = $(e.source).attr('data-uuid');
var targetId = $(e.target).attr('data-uuid');
var connectionId;

// Case 1:
// -------
// A new connection was created in the UI, but dropped before it reached
// a target, we can ignore it.
if (typeof targetId == 'undefined') { return; }
connectionId = idOfConnection(sourceId, targetId);

// Case 2:
// -------
// The connection model and its view have been removed from its
// collection, so its connection view was destroyed (along with the
// jsPlumb connection). We don't need to remove the connection model
// and view since they no longer exists.
if (!this.has(connectionId)) { return; }

// Case 2:
// Case 3:
// -------
// The connection was removed in the UI, so the model and view still
// exist. We need to remove them.
Expand Down
17 changes: 17 additions & 0 deletions go/base/static/js/test/components/plumbing/connections.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ describe("go.components.plumbing.connections", function() {

jsPlumb.detach(a1L2_b2R2.plumbConnection);
});

it("should ignore the event if the connection has no target", function() {
var a1L2 = diagram.endpoints.get('a1L2');
var b2R2 = diagram.endpoints.get('b2R2');
var a1L2_b2R2 = connections.get('a1L2-b2R2');
var plumbConnection = a1L2_b2R2.plumbConnection;

plumbConnection.target = null;
a1L2_b2R2.plumbConnection.target = null;

sinon.spy(console, 'log');
jsPlumb.detach(a1L2_b2R2.plumbConnection);

// jsPlumb logs errors instead of throwing them
assert(!console.log.called);
console.log.restore();
});
});
});
});

0 comments on commit 09123c4

Please sign in to comment.