From 303115953e195742927efdc1262d3a46d18f3c63 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 7 Jun 2019 07:16:52 -0700 Subject: [PATCH] Moved to #2125 disposal. Cleaned up some doc. --- core/field.js | 15 +++----- core/field_angle.js | 14 +------- core/field_colour.js | 3 +- core/field_date.js | 1 - core/field_dropdown.js | 14 +++----- core/field_image.js | 10 ------ core/field_textinput.js | 78 ++++++++++++++++++++++------------------- core/field_variable.js | 10 ------ 8 files changed, 52 insertions(+), 93 deletions(-) diff --git a/core/field.js b/core/field.js index f4b95e3da..ecd8469cb 100644 --- a/core/field.js +++ b/core/field.js @@ -327,7 +327,7 @@ Blockly.Field.prototype.toXml = function(fieldElement) { }; /** - * Dispose of all DOM objects belonging to this editable field. + * Dispose of all DOM objects and events belonging to this editable field. * @package */ Blockly.Field.prototype.dispose = function() { @@ -336,16 +336,11 @@ Blockly.Field.prototype.dispose = function() { if (this.mouseDownWrapper_) { Blockly.unbindEvent_(this.mouseDownWrapper_); - this.mouseDownWrapper_ = null; } - this.sourceBlock_ = null; - if (this.fieldGroup_) { - Blockly.utils.dom.removeNode(this.fieldGroup_); - this.fieldGroup_ = null; - } - this.textElement_ = null; - this.borderRect_ = null; - this.validator_ = null; + + Blockly.utils.dom.removeNode(this.fieldGroup_); + + this.disposed = true; }; /** diff --git a/core/field_angle.js b/core/field_angle.js index a3c3574d3..13e264216 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -130,15 +130,6 @@ Blockly.FieldAngle.prototype.initView = function() { this.textElement_.appendChild(this.symbol_); }; -/** - * Dispose of references to DOM elements and events belonging to this field. - * @package - */ -Blockly.FieldAngle.prototype.dispose = function() { - Blockly.FieldAngle.superClass_.dispose.call(this); - this.symbol_ = null; -}; - /** * Updates the graph when the field rerenders. * @private @@ -231,13 +222,10 @@ Blockly.FieldAngle.prototype.dropdownCreate_ = function() { }; /** - * Dispose of references to DOM elements and events belonging - * to the angle editor. + * Dispose of events belonging to the angle editor. * @private */ Blockly.FieldAngle.prototype.dropdownDispose_ = function() { - this.gauge_ = null; - this.line_ = null; Blockly.unbindEvent_(this.clickWrapper_); Blockly.unbindEvent_(this.moveWrapper1_); Blockly.unbindEvent_(this.moveWrapper2_); diff --git a/core/field_colour.js b/core/field_colour.js index 894f642f9..6fa02c696 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -332,8 +332,7 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { }; /** - * Dispose of references to DOM elements and events belonging - * to the colour editor. + * Dispose of events belonging to the colour editor. * @private */ Blockly.FieldColour.prototype.dropdownDispose_ = function() { diff --git a/core/field_date.js b/core/field_date.js index 843d53562..83f6a1c34 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -240,7 +240,6 @@ Blockly.FieldDate.prototype.dropdownCreate_ = function() { * @private */ Blockly.FieldDate.prototype.dropdownDispose_ = function() { - this.picker_ = null; goog.events.unlistenByKey(this.changeEventKey_); goog.events.unlistenByKey(this.activeMonthEventKey_); }; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5b1272f2d..fd6863f7e 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -154,15 +154,6 @@ Blockly.FieldDropdown.prototype.initView = function() { } }; -/** - * Dispose of references to DOM elements and events belonging to this field. - */ -Blockly.FieldDropdown.prototype.dispose = function() { - Blockly.FieldDropdown.superClass_.dispose.call(this); - this.imageElement_ = null; - this.arrow_ = null; -}; - /** * Create a dropdown menu under the text. * @private @@ -223,8 +214,11 @@ Blockly.FieldDropdown.prototype.widgetCreate_ = function() { return menu; }; +/** + * Dispose of events belonging to the dropdown editor. + * @private + */ Blockly.FieldDropdown.prototype.widgetDispose_ = function() { - this.menu_ = null; goog.events.unlistenByKey(this.menuActionEventKey_); }; diff --git a/core/field_image.js b/core/field_image.js index 7a7bb96ec..bd5a56ae1 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -129,16 +129,6 @@ Blockly.FieldImage.prototype.initView = function() { 'xlink:href', this.value_); }; -/** - * Dispose of all DOM objects belonging to this text. - */ -Blockly.FieldImage.prototype.dispose = function() { - Blockly.FieldImage.superClass_.dispose.call(this); - this.imageElement_ = null; - // TODO: Do we need to dispose of this? - this.clickHandler_ = null; -}; - /** * Ensure that the input value (the source URL) is a string. * @param {string=} newValue The input value diff --git a/core/field_textinput.js b/core/field_textinput.js index 20636c8e8..089d62b8f 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -232,6 +232,11 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { } }; +/** + * Create the text input editor widget. + * @return {HTMLInputElement} The newly created text input editor. + * @private + */ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { var div = Blockly.WidgetDiv.DIV; @@ -254,6 +259,42 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { return htmlInput; }; +/** + * Close the editor, save the results, and dispose any events bound to the + * text input's editor. + * @private + */ +Blockly.FieldTextInput.prototype.widgetDispose_ = function() { + // Finalize value. + this.isBeingEdited_ = false; + // No need to call setValue because if the widget is being closed the + // latest input text has already been validated. + if (this.value_ !== this.text_) { + // At the end of an edit the text should be the same as the value. It + // may not be if the input text is different than the validated text. + // We should fix that. + this.text_ = String(this.value_); + this.isTextValid_ = true; + this.forceRerender(); + } + // Otherwise don't rerender. + + // Call onFinishEditing + // TODO: Get rid of this or make it less of a hack. + if (this.onFinishEditing_) { + this.onFinishEditing_(this.value_); + } + + // Remove htmlInput events. + this.unbindInputEvents_(); + + // Delete style properties. + var style = Blockly.WidgetDiv.DIV.style; + style.width = 'auto'; + style.height = 'auto'; + style.fontSize = ''; +}; + /** * Bind handlers for user input on the text input field's editor. * @param {!HTMLInputElement} htmlInput The htmlInput to which event @@ -365,43 +406,6 @@ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { div.style.top = xy.y + 'px'; }; -/** - * Close the editor, save the results, and dispose of the editable - * text field's elements. - * @private - */ -Blockly.FieldTextInput.prototype.widgetDispose_ = function() { - // Finalize value. - this.isBeingEdited_ = false; - // No need to call setValue because if the widget is being closed the - // latest input text has already been validated. - if (this.value_ !== this.text_) { - // At the end of an edit the text should be the same as the value. It - // may not be if the input text is different than the validated text. - // We should fix that. - this.text_ = String(this.value_); - this.isTextValid_ = true; - this.forceRerender(); - } - // Otherwise don't rerender. - - // Call onFinishEditing - // TODO: Get rid of this or make it less of a hack. - if (this.onFinishEditing_) { - this.onFinishEditing_(this.value_); - } - - // Remove htmlInput. - this.unbindInputEvents_(); - this.htmlInput_ = null; - - // Delete style properties. - var style = Blockly.WidgetDiv.DIV.style; - style.width = 'auto'; - style.height = 'auto'; - style.fontSize = ''; -}; - /** * Ensure that only a number may be entered. * @param {string} text The user's text. diff --git a/core/field_variable.js b/core/field_variable.js index 29aa44a0c..278fe5c55 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -157,16 +157,6 @@ Blockly.FieldVariable.prototype.toXml = function(fieldElement) { return fieldElement; }; -/** - * Dispose of this field. - * @public - */ -Blockly.FieldVariable.prototype.dispose = function() { - Blockly.FieldVariable.superClass_.dispose.call(this); - this.workspace_ = null; - this.variableMap_ = null; -}; - /** * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field.