From 84c739c81a3a986f2c1606d70c34104d89aa6cf4 Mon Sep 17 00:00:00 2001
From: Christopher Willis-Ford <cwillisf@media.mit.edu>
Date: Thu, 31 Aug 2017 11:15:19 -0700
Subject: [PATCH] Explain need for `setToolboxSelectedItemByName`

---
 src/containers/blocks.jsx | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx
index 9f7831e81..20b13d3ea 100644
--- a/src/containers/blocks.jsx
+++ b/src/containers/blocks.jsx
@@ -70,6 +70,8 @@ class Blocks extends React.Component {
         if (prevProps.toolboxXML !== this.props.toolboxXML) {
             const selectedCategoryName = this.workspace.toolbox_.getSelectedItem().name_;
             this.workspace.updateToolbox(this.props.toolboxXML);
+            // Blockly throws if we don't select a category after updating the toolbox.
+            /** @TODO Find a way to avoid the exception without accessing private properties. */
             this.setToolboxSelectedItemByName(selectedCategoryName);
         }
         if (this.props.isVisible === prevProps.isVisible) {
@@ -91,6 +93,12 @@ class Blocks extends React.Component {
         this.detachVM();
         this.workspace.dispose();
     }
+    /**
+     * Select a particular category in the toolbox by specifying the category name.
+     * This is a workaround for a bug: @see {@link componentDidUpdate} above.
+     * @TODO Remove this or reimplement using only public APIs.
+     * @param {string} name - the name of the category to select.
+     */
     setToolboxSelectedItemByName (name) {
         const categories = this.workspace.toolbox_.categoryMenu_.categories_;
         for (let i = 0; i < categories.length; i++) {
-- 
GitLab