From e28db7bc4e8141565caf7a60a31b0e1a6a266e4c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 10 May 2016 15:39:37 -0700 Subject: [PATCH] JS Doc and private --- core/block.js | 17 +++++++++++----- core/block_svg.js | 8 +++++++- core/connection.js | 32 +++++++++++++++++++---------- core/rendered_connection.js | 40 ++++++++++++++++++++++++++++--------- 4 files changed, 72 insertions(+), 25 deletions(-) diff --git a/core/block.js b/core/block.js index 74746d037..bf6041416 100644 --- a/core/block.js +++ b/core/block.js @@ -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); }; diff --git a/core/block_svg.js b/core/block_svg.js index 3cd9a4c52..cbf436fa1 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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); }; diff --git a/core/connection.js b/core/connection.js index 27f3ae58e..84c35dd93 100644 --- a/core/connection.js +++ b/core/connection.js @@ -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.'; } diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 1be374afc..ac171ddae 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -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);