Skip to content

Created separate file for VariableMap#1079

Merged
marisaleung merged 5 commits intoRaspberryPiFoundation:developfrom
marisaleung:develop
May 4, 2017
Merged

Created separate file for VariableMap#1079
marisaleung merged 5 commits intoRaspberryPiFoundation:developfrom
marisaleung:develop

Conversation

@marisaleung
Copy link
Copy Markdown
Contributor

@marisaleung marisaleung commented May 3, 2017

This change is Reviewable

@rachel-fenichel
Copy link
Copy Markdown
Collaborator

Unit tests are failing, since you added a new file.

Please rebuild and add only blockly_uncompressed.js to this PR.

@marisaleung
Copy link
Copy Markdown
Contributor Author

marisaleung commented May 3, 2017 via email

Copy link
Copy Markdown
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits but generally looks good to me.

Can any of the workspace tests be moved into a new test file, now that you've moved a bunch of the logic to be internal to VariableMap?

Github says you've got merge markers left in your uncompressed file.

this.createVariable(newName, '');
console.log('Tried to rename an non-existent variable.');
}
else if (variableIndex == newVariableIndex ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Move the else if onto the previous line

+ variable.getId() + '" which conflicts with the passed in ' +
'id, "' + opt_id + '".');
}
return;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case where nothing went wrong but the variable already existed, correct? If so, add a comment: "// The variable already exists and has the same id and type."

this.variableMap_[opt_type] = [variable];
}
// Else append the variable to the preexisting list.
else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else should share a line with the previous closing brace. You can just put the comment inside here, or else remove it.

*/
Blockly.VariableMap.prototype.deleteVariable = function(variable) {
var type = variable.type;
for (var i = 0, tempVar; tempVar = this.variableMap_[type][i]; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store this.variableMap_[type] in a variable outside of the loop for clarity.

Blockly.VariableMap.prototype.deleteVariable = function(variable) {
var type = variable.type;
for (var i = 0, tempVar; tempVar = this.variableMap_[type][i]; i++) {
if (Blockly.Names.equals(tempVar.name, variable.name)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check by id? Then you don't have to depend on additional blockly code--it's just a string comparison.

var type = variable.type;
for (var i = 0, tempVar; tempVar = this.variableMap_[type][i]; i++) {
if (Blockly.Names.equals(tempVar.name, variable.name)) {
delete this.variableMap_[type][i];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need to call delete--it should get handled by gc once it's removed from the list, and variableModel doesn't have any special disposal code.

* Find the variable by the given name and return it. Return null if it is not
* found.
* @param {!string} name The name to check for.
* @return {?Blockly.VariableModel} the variable with the given name.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable with the given name, or null if it was not found.

};

/**
* Find the variable with the specified type. If type is null, return list of
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Get a list containing all of the variables of a specified type. If type is null, ..."

@marisaleung
Copy link
Copy Markdown
Contributor Author

Review status: 0 of 6 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed.


core/variable_map.js, line 80 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

Nit: Move the else if onto the previous line

Done.


core/variable_map.js, line 115 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

This is the case where nothing went wrong but the variable already existed, correct? If so, add a comment: "// The variable already exists and has the same id and type."

Done.


core/variable_map.js, line 129 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

nit: else should share a line with the previous closing brace. You can just put the comment inside here, or else remove it.

Done.


core/variable_map.js, line 140 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

Store this.variableMap_[type] in a variable outside of the loop for clarity.

Done.


core/variable_map.js, line 141 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

Why not check by id? Then you don't have to depend on additional blockly code--it's just a string comparison.

Good point.
Done.


core/variable_map.js, line 142 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

I think you don't need to call delete--it should get handled by gc once it's removed from the list, and variableModel doesn't have any special disposal code.

You are right. Took it out.


core/variable_map.js, line 153 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

the variable with the given name, or null if it was not found.

Done.


core/variable_map.js, line 188 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

"Get a list containing all of the variables of a specified type. If type is null, ..."

Done.


Comments from Reviewable

@marisaleung
Copy link
Copy Markdown
Contributor Author

All tests that just pass through workspace to variable_map functions have been put into a separate file called "variable_map_tests.js".

@rachel-fenichel
Copy link
Copy Markdown
Collaborator

:lgtm: if you can get blockly_uncompressed to behave.


Reviewed 1 of 4 files at r1, 4 of 4 files at r2.
Review status: 5 of 6 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


Comments from Reviewable

@marisaleung marisaleung merged commit ee58eb4 into RaspberryPiFoundation:develop May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants