Skip to content

Commit

Permalink
Initial work on allowing ports to decline new connections, refs #74
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Oct 2, 2013
1 parent 56b2c3a commit 3bc0dfb
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
29 changes: 26 additions & 3 deletions build/dataflow.build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! dataflow.js - v0.0.7 - 2013-10-02 (5:27:30 PM GMT+0200)
/*! dataflow.js - v0.0.7 - 2013-10-02 (6:20:43 PM GMT+0200)
* Copyright (c) 2013 Forrest Oliphant; Licensed MIT, GPL */
// Thanks bobnice http://stackoverflow.com/a/1583281/592125

Expand Down Expand Up @@ -710,7 +710,8 @@ CircularBuffer.IndexError= {};
id: "input",
description: "",
label: "",
type: "all"
type: "all",
multiple: true
},
initialize: function() {
this.parentNode = this.get("parentNode");
Expand All @@ -719,7 +720,18 @@ CircularBuffer.IndexError= {};
}
this.connected = [];
},
canConnect: function (edge) {
if (!this.get('multiple') && this.connected.length) {
// This port doesn't allow multiple connections and
// there is a connection already, decline
return false;
}
return true;
},
connect: function(edge){
if (!this.canConnect(edge)) {
return;
}
this.connected.push(edge);
this.connected = _.uniq(this.connected);
this.trigger('connected');
Expand Down Expand Up @@ -757,7 +769,8 @@ CircularBuffer.IndexError= {};
id: "output",
label: "",
type: "all",
description: ""
description: "",
multiple: true
}
});

Expand Down Expand Up @@ -1924,6 +1937,11 @@ CircularBuffer.IndexError= {};
return false;
}

if (!this.model.canConnect()) {
// Port declined the connection, abort
return;
}

var route = 0;
if (ui.helper.data("route") !== undefined) {
route = ui.helper.data("route");
Expand Down Expand Up @@ -2226,6 +2244,11 @@ CircularBuffer.IndexError= {};
return false;
}

if (!this.model.canConnect()) {
// Port declined the connection, abort
return;
}

var route = 0;
if (ui.helper.data("route") !== undefined) {
route = ui.helper.data("route");
Expand Down
6 changes: 3 additions & 3 deletions build/dataflow.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/dataflow.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
data: 'random'
});
}, 500);
// Set one port to decline multiple connections
dataflow.graph.get('nodes').at(2).inputs.at(1).set('multiple', false);

window.d = $(".dataflow").data("dataflow");
});
Expand Down
5 changes: 5 additions & 0 deletions src/modules/input-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@
return false;
}

if (!this.model.canConnect()) {
// Port declined the connection, abort
return;
}

var route = 0;
if (ui.helper.data("route") !== undefined) {
route = ui.helper.data("route");
Expand Down
14 changes: 13 additions & 1 deletion src/modules/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
id: "input",
description: "",
label: "",
type: "all"
type: "all",
multiple: true
},
initialize: function() {
this.parentNode = this.get("parentNode");
Expand All @@ -16,7 +17,18 @@
}
this.connected = [];
},
canConnect: function (edge) {
if (!this.get('multiple') && this.connected.length) {
// This port doesn't allow multiple connections and
// there is a connection already, decline
return false;
}
return true;
},
connect: function(edge){
if (!this.canConnect(edge)) {
return;
}
this.connected.push(edge);
this.connected = _.uniq(this.connected);
this.trigger('connected');
Expand Down
5 changes: 5 additions & 0 deletions src/modules/output-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@
return false;
}

if (!this.model.canConnect()) {
// Port declined the connection, abort
return;
}

var route = 0;
if (ui.helper.data("route") !== undefined) {
route = ui.helper.data("route");
Expand Down
3 changes: 2 additions & 1 deletion src/modules/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
id: "output",
label: "",
type: "all",
description: ""
description: "",
multiple: true
}
});

Expand Down

0 comments on commit 3bc0dfb

Please sign in to comment.