Workflow Editor: Rework InputTerminal to implement/use an update method (w/tests).

This will enable replacing terminals instead of recreating them and reconnecting in subsequent changesets.
This commit is contained in:
John Chilton
2014-04-22 11:13:27 -05:00
parent 10d5c0f920
commit 553bbee7db
2 changed files with 18 additions and 8 deletions
@@ -38,8 +38,11 @@ var OutputTerminal = Terminal.extend( {
var InputTerminal = Terminal.extend( {
initialize: function( attr ) {
Terminal.prototype.initialize.call( this, attr );
this.datatypes = attr.datatypes;
this.multiple = attr.multiple;
this.update( attr.input );
},
update: function( input ) {
this.datatypes = input.extensions;
this.multiple = input.multiple;
},
canAccept: function ( other ) {
if( this._inputFilled() ) {
@@ -981,13 +984,9 @@ var InputTerminalView = Backbone.View.extend( {
var input = options.input;
var name = input.name;
var types = input.extensions;
var multiple = input.multiple;
var terminal = this.el.terminal = new InputTerminal( { element: this.el, datatypes: types, multiple: multiple } );
var terminal = this.el.terminal = new InputTerminal( { element: this.el, input: input } );
terminal.node = node;
terminal.name = name;
node.input_terminals[name] = terminal;
},
+12 -1
View File
@@ -63,7 +63,8 @@ define([
setup: function() {
this.node = { };
this.element = $( "<div>" );
this.input_terminal = new InputTerminal( { element: this.element, datatypes: [ "txt" ] } );
var input = { extensions: [ "txt" ], multiple: false };
this.input_terminal = new InputTerminal( { element: this.element, input: input } );
this.input_terminal.node = this.node;
},
test_connector: function( attr ) {
@@ -90,6 +91,16 @@ define([
}
} );
test( "test update", function() {
deepEqual( this.input_terminal.datatypes, [ 'txt' ] );
equal( this.input_terminal.multiple, false );
this.input_terminal.update( { extensions: [ 'bam' ], multiple: true } );
deepEqual( this.input_terminal.datatypes, [ 'bam' ] );
equal( this.input_terminal.multiple, true );
} );
test( "test connect", function() {
this.node.markChanged = sinon.spy();