JS Doc and private

This commit is contained in:
Rachel Fenichel
2016-05-10 15:39:37 -07:00
parent ae745dac80
commit e28db7bc4e
4 changed files with 72 additions and 25 deletions

View File

@@ -746,7 +746,8 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
if (!this.previousConnection) {
goog.asserts.assert(!this.outputConnection,
'Remove output connection prior to adding previous connection.');
this.previousConnection = this.makeConnection(Blockly.PREVIOUS_STATEMENT);
this.previousConnection =
this.makeConnection_(Blockly.PREVIOUS_STATEMENT);
}
this.previousConnection.setCheck(opt_check);
} else {
@@ -771,7 +772,7 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) {
opt_check = null;
}
if (!this.nextConnection) {
this.nextConnection = this.makeConnection(Blockly.NEXT_STATEMENT);
this.nextConnection = this.makeConnection_(Blockly.NEXT_STATEMENT);
}
this.nextConnection.setCheck(opt_check);
} else {
@@ -799,7 +800,7 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) {
if (!this.outputConnection) {
goog.asserts.assert(!this.previousConnection,
'Remove previous connection prior to adding output connection.');
this.outputConnection = this.makeConnection(Blockly.OUTPUT_VALUE);
this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE);
}
this.outputConnection.setCheck(opt_check);
} else {
@@ -1156,7 +1157,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
Blockly.Block.prototype.appendInput_ = function(type, name) {
var connection = null;
if (type == Blockly.INPUT_VALUE || type == Blockly.NEXT_STATEMENT) {
connection = this.makeConnection(type);
connection = this.makeConnection_(type);
}
var input = new Blockly.Input(type, name, this, connection);
// Append input to list.
@@ -1334,6 +1335,12 @@ Blockly.Block.prototype.moveBy = function(dx, dy) {
Blockly.Events.fire(event);
};
Blockly.Block.prototype.makeConnection = function(type) {
/**
* Create a connection of the specified type.
* @param {number} type The type of the connection to create.
* @return {!Blockly.Connection} A new connection of the specified type.
* @private
*/
Blockly.Block.prototype.makeConnection_ = function(type) {
return new Blockly.Connection(this, type);
};

View File

@@ -1590,6 +1590,12 @@ Blockly.BlockSvg.prototype.getConnections_ = function(all) {
return myConnections;
};
Blockly.BlockSvg.prototype.makeConnection = function(type) {
/**
* Create a connection of the specified type.
* @param {number} type The type of the connection to create.
* @return {!Blockly.RenderedConnection} A new connection of the specified type.
* @private
*/
Blockly.BlockSvg.prototype.makeConnection_ = function(type) {
return new Blockly.RenderedConnection(this, type);
};

View File

@@ -484,16 +484,23 @@ Blockly.Connection.prototype.disconnect = function() {
childBlock = this.sourceBlock_;
parentConnection = otherConnection;
}
this.disconnectInternal(parentBlock, childBlock, otherConnection);
this.respawnShadow(parentConnection, parentBlock);
this.disconnectInternal_(parentBlock, childBlock);
parentConnection.respawnShadow_();
};
Blockly.Connection.prototype.disconnectInternal = function(parentBlock,
childBlock, otherConnection) {
/**
* Disconnect two blocks that are connected by this connection.
* @param {!Blockly.Block} parentBlock The superior block.
* @param {!Blockly.Block} childBlock The inferior block.
* @private
*/
Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock,
childBlock) {
var event;
if (Blockly.Events.isEnabled()) {
event = new Blockly.Events.Move(childBlock);
}
var otherConnection = this.targetConnection;
otherConnection.targetConnection = null;
this.targetConnection = null;
childBlock.setParent(null);
@@ -503,17 +510,22 @@ Blockly.Connection.prototype.disconnectInternal = function(parentBlock,
}
};
Blockly.Connection.prototype.respawnShadow = function(parentConnection,
parentBlock) {
// Respawn the shadow block if there is one.
var shadow = parentConnection.getShadowDom();
/**
* Respawn the shadow block if there was one connected to the this connection.
* @return {Blockly.Block} The newly spawned shadow block, or null if none was
* spawned.
* @private
*/
Blockly.Connection.prototype.respawnShadow_ = function() {
var parentBlock = this.getSourceBlock();
var shadow = this.getShadowDom();
if (parentBlock.workspace && shadow && Blockly.Events.recordUndo) {
var blockShadow =
Blockly.Xml.domToBlock(shadow, parentBlock.workspace);
if (blockShadow.outputConnection) {
parentConnection.connect(blockShadow.outputConnection);
this.connect(blockShadow.outputConnection);
} else if (blockShadow.previousConnection) {
parentConnection.connect(blockShadow.previousConnection);
this.connect(blockShadow.previousConnection);
} else {
throw 'Child block does not have output or previous statement.';
}

View File

@@ -285,10 +285,16 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate,
candidate);
};
Blockly.RenderedConnection.prototype.disconnectInternal = function(parentBlock,
childBlock, otherConnection) {
Blockly.RenderedConnection.superClass_.disconnectInternal.call(this,
parentBlock, childBlock, otherConnection);
/**
* Disconnect two blocks that are connected by this connection.
* @param {!Blockly.Block} parentBlock The superior block.
* @param {!Blockly.Block} childBlock The inferior block.
* @private
*/
Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock,
childBlock) {
Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this,
parentBlock, childBlock);
// Rerender the parent so that it may reflow.
if (parentBlock.rendered) {
parentBlock.render();
@@ -299,16 +305,26 @@ Blockly.RenderedConnection.prototype.disconnectInternal = function(parentBlock,
}
};
Blockly.RenderedConnection.prototype.respawnShadow = function(parentConnection,
parentBlock) {
/**
* Respawn the shadow block if there was one connected to the this connection.
* Render/rerender blocks as needed.
* @private
*/
Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
var parentBlock = this.getSourceBlock();
// Respawn the shadow block if there is one.
var shadow = parentConnection.getShadowDom();
var shadow = this.getShadowDom();
if (parentBlock.workspace && shadow && Blockly.Events.recordUndo) {
var blockShadow =
Blockly.RenderedConnection.superClass_.respawnShadow.call(this,
parentConnection, parentBlock, childBlock);
Blockly.RenderedConnection.superClass_.respawnShadow_.call(this);
if (!blockShadow) {
throw 'Couldn\'t respawn the shadow block that should exist here.';
}
blockShadow.initSvg();
blockShadow.render(false);
if (parentBlock.rendered) {
parentBlock.render();
}
}
};
@@ -323,6 +339,12 @@ Blockly.RenderedConnection.prototype.neighbours_ = function(maxLimit) {
return this.dbOpposite_.getNeighbours(this, maxLimit);
};
/**
* Connect two connections together. This is the connection on the superior
* block. Rerender blocks as needed.
* @param {!Blockly.Connection} childConnection Connection on inferior block.
* @private
*/
Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection);