Skip to content

Commit

Permalink
Use prototypes for primitive properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Sep 13, 2015
1 parent 1b43699 commit 3f8e586
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 31 deletions.
8 changes: 4 additions & 4 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ Blockly.Connection.prototype.targetConnection = null;

/**
* List of compatible value types. Null if all types are compatible.
* @private
* @type {Array}
* @private
*/
Blockly.Connection.prototype.check_ = null;

/**
* Horizontal location of this connection.
* @private
* @type {number}
* @private
*/
Blockly.Connection.prototype.x_ = 0;

/**
* Vertical location of this connection.
* @private
* @type {number}
* @private
*/
Blockly.Connection.prototype.y_ = 0;

/**
* Has this connection been added to the connection database?
* @private
* @type {boolean}
* @private
*/
Blockly.Connection.prototype.inDB_ = false;

Expand Down
18 changes: 14 additions & 4 deletions core/field_colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,23 @@ Blockly.FieldColour = function(colour, opt_changeHandler) {
this.setChangeHandler(opt_changeHandler);
// Set the initial state.
this.setValue(colour);

// By default use the global constants for colours and columns.
this.colours_ = null;
this.columns_ = 0;
};
goog.inherits(Blockly.FieldColour, Blockly.Field);

/**
* By default use the global constants for colours.
* @type {Array.<string>}
* @private
*/
Blockly.FieldColour.prototype.colours_ = null;

/**
* By default use the global constants for columns.
* @type {number}
* @private
*/
Blockly.FieldColour.prototype.columns_ = 0;

/**
* Install this field on a block.
* @param {!Blockly.Block} block The block containing this field.
Expand Down
1 change: 0 additions & 1 deletion core/field_label.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ goog.require('goog.math.Size');
* @constructor
*/
Blockly.FieldLabel = function(text, opt_class) {
this.sourceBlock_ = null;
this.size_ = new goog.math.Size(0, 17.5);
this.class_ = opt_class;
this.setText(text);
Expand Down
28 changes: 15 additions & 13 deletions core/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,11 @@ Blockly.Flyout = function(workspaceOptions) {

/**
* Opaque data that can be passed to Blockly.unbindEvent_.
* @type {Array.<!Array>}
* @type {!Array.<!Array>}
* @private
*/
this.eventWrappers_ = [];

/**
* @type {number}
* @private
*/
this.width_ = 0;

/**
* @type {number}
* @private
*/
this.height_ = 0;

/**
* List of background buttons that lurk behind each block to catch clicks
* landing in the blocks' lakes and bays.
Expand Down Expand Up @@ -113,6 +101,20 @@ Blockly.Flyout.prototype.CORNER_RADIUS = 8;
*/
Blockly.Flyout.prototype.SCROLLBAR_PADDING = 2;

/**
* Width of flyout.
* @type {number}
* @private
*/
Blockly.Flyout.prototype.width_ = 0;

/**
* Height of flyout.
* @type {number}
* @private
*/
Blockly.Flyout.prototype.height_ = 0;

/**
* Creates the flyout's DOM. Only needs to be called once.
* @return {!Element} The flyout's SVG group.
Expand Down
10 changes: 9 additions & 1 deletion core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ goog.require('goog.asserts');
*/
Blockly.Generator = function(name) {
this.name_ = name;
this.RESERVED_WORDS_ = '';
this.FUNCTION_NAME_PLACEHOLDER_REGEXP_ =
new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g');
};
Expand Down Expand Up @@ -270,9 +269,17 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, id) {
/**
* The method of indenting. Defaults to two spaces, but language generators
* may override this to increase indent or change to tabs.
* @type {string}
*/
Blockly.Generator.prototype.INDENT = ' ';

/**
* Comma-separated list of reserved words.
* @type {string}
* @private
*/
Blockly.Generator.prototype.RESERVED_WORDS_ = '';

/**
* Add one or more words to the list of reserved words for this language.
* @param {string} words Comma-separated list of words to add to the list.
Expand All @@ -287,6 +294,7 @@ Blockly.Generator.prototype.addReservedWords = function(words) {
* Blockly.Generator.provideFunction_. It must not be legal code that could
* legitimately appear in a function definition (or comment), and it must
* not confuse the regular expression parser.
* @type {string}
* @private
*/
Blockly.Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}';
Expand Down
17 changes: 13 additions & 4 deletions core/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ Blockly.Input = function(type, name, block, connection) {
this.connection = connection;
/** @type {!Array.<!Blockly.Field>} */
this.fieldRow = [];
/** @type {number} */
this.align = Blockly.ALIGN_LEFT;
/** @type {boolean} */
this.visible_ = true;
};

/**
* Alignment of input's fields (left, right or centre).
* @type {number}
*/
Blockly.Input.prototype.align = Blockly.ALIGN_LEFT;

/**
* Is the input visible?
* @type {boolean}
* @private
*/
Blockly.Input.prototype.visible_ = true;

/**
* Add an item to the end of the input's field row.
* @param {string|!Blockly.Field} field Something to add as a field.
Expand Down
8 changes: 7 additions & 1 deletion core/scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ goog.require('goog.events');
*/
Blockly.ScrollbarPair = function(workspace) {
this.workspace_ = workspace;
this.oldHostMetrics_ = null;
this.hScroll = new Blockly.Scrollbar(workspace, true, true);
this.vScroll = new Blockly.Scrollbar(workspace, false, true);
this.corner_ = Blockly.createSvgElement('rect',
Expand All @@ -48,6 +47,13 @@ Blockly.ScrollbarPair = function(workspace) {
Blockly.Scrollbar.insertAfter_(this.corner_, workspace.getBubbleCanvas());
};

/**
* Previously recorded metrics from the workspace.
* @type {Object}
* @private
*/
Blockly.ScrollbarPair.prototype.oldHostMetrics_ = null;

/**
* Dispose of this pair of scrollbars.
* Unlink from all DOM elements to prevent memory leaks.
Expand Down
4 changes: 2 additions & 2 deletions core/widgetdiv.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ Blockly.WidgetDiv.DIV = null;

/**
* The object currently using this container.
* @private
* @type {Object}
* @private
*/
Blockly.WidgetDiv.owner_ = null;

/**
* Optional cleanup function set by whichever object uses the widget.
* @private
* @type {Function}
* @private
*/
Blockly.WidgetDiv.dispose_ = null;

Expand Down
2 changes: 1 addition & 1 deletion core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Blockly.WorkspaceSvg = function(options) {

/**
* Opaque data that can be passed to Blockly.unbindEvent_.
* @type {Array.<!Array>}
* @type {!Array.<!Array>}
* @private
*/
this.eventWrappers_ = [];
Expand Down

0 comments on commit 3f8e586

Please sign in to comment.