VariableMap and functions added.#1071
VariableMap and functions added.#1071marisaleung merged 1 commit intoRaspberryPiFoundation:developfrom
Conversation
|
Review status: 0 of 11 files reviewed at latest revision, 17 unresolved discussions. core/variables.js, line 91 at r1 (raw file):
allVariables should probably return a list containing every variable in the map. Generators will need this to create the set of initializers for everything. You can do this by iterating through the keys and adding each type's list of variables to the full list before returning it. core/variables.js, line 165 at r1 (raw file):
allVariables. This name should be unique across everything, not just the empty type. core/workspace.js, line 84 at r1 (raw file):
Make this private while you're at it. That way we won't have to break devs again if we ever change this data structure in the future. core/workspace.js, line 197 at r1 (raw file):
Why do you need to do this much work? You should be able to just clear the map and let gc clean up the individual lists. core/workspace.js, line 211 at r1 (raw file):
Revert method name change. Let's keep as much of the API as we can. core/workspace.js, line 227 at r1 (raw file):
Please add a TODO to use variable.type and variable.getId() once variable instances are storing more than just name. core/workspace.js, line 279 at r1 (raw file):
Instead of iterating through manually if you get the list for just the type of interest and you can use the old code as is. core/workspace.js, line 282 at r1 (raw file):
Add a TODO to update all variable references to point to the new id once they're storing more than just name. core/workspace.js, line 302 at r1 (raw file):
renameVariableInstance = function(variable, newName) where variable is an instance of variable including the id, name, and type might make the implementation easier. Fine to use this as a helper if there are places where you have the id without the full variable instance. core/workspace.js, line 321 at r1 (raw file):
You should check that either the type/id aren't set or that they match the existing variable. core/workspace.js, line 365 at r1 (raw file):
remove s on 'variables' core/workspace.js, line 419 at r1 (raw file):
Not in scope for this CL, but in a followup CL you should convert all the internal calls to take a VariableModel or id instead of the name since the name may not correctly identify the variable. Also, if you take the model you only need to check the list with the correct type and can use variableList = getVariablesOfType() core/workspace.js, line 431 at r1 (raw file):
Once the variable has been found and removed you can exit the loop. core/workspace.js, line 622 at r1 (raw file):
if type is null, returns all variables with the empty string type. core/workspace.js, line 628 at r1 (raw file):
Just do type = type || ''; core/workspace.js, line 635 at r1 (raw file):
Prefer you push the VariableModel object. We're going to want to start using it more throughout the code so we can refer to the type and the id. core/workspace.js, line 654 at r1 (raw file):
return Blockly.Variables.allVariables(this); Comments from Reviewable |
|
Review status: 0 of 11 files reviewed at latest revision, 20 unresolved discussions. core/variables.js, line 225 at r1 (raw file):
What's going on here? Why do you care about procedures here? core/workspace.js, line 84 at r1 (raw file): Previously, RoboErikG wrote…
+1 core/workspace.js, line 131 at r1 (raw file):
for...of is not supported in Internet Explorer: https://docs.microsoft.com/en-us/scripting/javascript/reference/for-dot-dot-dot-of-statement-javascript#requirements core/workspace.js, line 211 at r1 (raw file): Previously, RoboErikG wrote…
I'm less concerned about preserving the current API (it's not that old) than I am with making sure that the names match what's actually happening in the future. So I would rather switch to updateVariableMap, or else something generic like updateVariableStore. If you are updating the name, update the parameter core/workspace.js, line 214 at r1 (raw file):
Missing semicolon. Comments from Reviewable |
|
Review status: 0 of 11 files reviewed at latest revision, 24 unresolved discussions. tests/jsunit/workspace_test.js, line 27 at r1 (raw file):
You should change this message in setUp and tearDown, or (even better) only in test cases where it'll be used. Make sure you reset it at the end, and add a comment explaining why you need to define this (which function uses it, and why it's set to this particular value). tests/jsunit/workspace_test.js, line 79 at r1 (raw file):
I prefer to keep assignments out of asserts whenever possible. I would do tests/jsunit/workspace_test.js, line 82 at r1 (raw file):
Why do you access variable.name and variable.type directly, but the id though variable.getId()? tests/jsunit/workspace_test.js, line 145 at r1 (raw file):
You may no longer need to dispose of the blocks manually, as they may be disposed of by workspace dispose. In that case you would also not need to declare them outside of the try. Same applies to all of these tests. Comments from Reviewable |
|
Review status: 0 of 11 files reviewed at latest revision, 24 unresolved discussions. tests/jsunit/workspace_test.js, line 82 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
It's because the ID is read only, so it has an accessor but no setter. Comments from Reviewable |
|
Review status: 0 of 11 files reviewed at latest revision, 24 unresolved discussions. core/variables.js, line 91 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/variables.js, line 165 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/variables.js, line 225 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Following Design Doc and checking that name is unique across all variables and procedures. If you want me to move that to a different CL, let me know. core/workspace.js, line 84 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 131 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Discussed offline to use a format like this: Changed each for loop to not use for...of Done. core/workspace.js, line 197 at r1 (raw file): Previously, RoboErikG wrote…
Hm I thought I had been running into a problem in the tests where garbage collection wasn't working. Anywho, this.variableMap_ = {} currently passes all the tests so I'll use that. core/workspace.js, line 211 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
I change it to updateVariableStore and changed clearList to clear. Let me know if you want me to revert or do something else. core/workspace.js, line 214 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 227 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 279 at r1 (raw file): Previously, RoboErikG wrote…
Yay reusing code! Thank you for the reminder. Done. core/workspace.js, line 282 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 302 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 321 at r1 (raw file): Previously, RoboErikG wrote…
core/workspace.js, line 365 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 431 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 622 at r1 (raw file): Previously, RoboErikG wrote…
Done. Function Description updated too. core/workspace.js, line 628 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 635 at r1 (raw file): Previously, RoboErikG wrote…
Done. core/workspace.js, line 654 at r1 (raw file): Previously, RoboErikG wrote…
Actually, I have Blockly.Variables.allVariables() call this function instead of the other way around. I think it makes sense to keep the actual searching in workspace.js because variableMap_ is there. What do you think? tests/jsunit/workspace_test.js, line 27 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. tests/jsunit/workspace_test.js, line 79 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. And fixed throughout the rest of the tests I created. tests/jsunit/workspace_test.js, line 82 at r1 (raw file): Previously, RoboErikG wrote…
Done. tests/jsunit/workspace_test.js, line 145 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. Comments from Reviewable |
|
Review status: 0 of 11 files reviewed at latest revision, 24 unresolved discussions. core/workspace.js, line 84 at r1 (raw file): Previously, marisaleung wrote…
Done. core/workspace.js, line 419 at r1 (raw file): Previously, RoboErikG wrote…
Acknowledged! Comments from Reviewable |
2994805 to
78c84ca
Compare
|
Review status: 0 of 11 files reviewed at latest revision, 22 unresolved discussions. core/workspace.js, line 321 at r1 (raw file): Previously, marisaleung wrote…
Offline we decided: Comments from Reviewable |
|
Reviewed 1 of 11 files at r1, 1 of 4 files at r2. core/variables.js, line 225 at r1 (raw file): Previously, marisaleung wrote…
Where is that specified in the design doc? I don't think that's behaviour that we want. core/variables.js, line 89 at r2 (raw file):
Return early if it's a block, or else get the workspace from the block and update the message to say that you're making a best guess at the workspace. This was a preexisting bug, but now it'll break instead of returning undefined. core/workspace.js, line 132 at r2 (raw file):
Since there's now a distinction between a variable name (a string) and a variable (a variableModel), use "name" instead of "variable" here. That makes the following code which reads more cleanly. core/workspace.js, line 211 at r2 (raw file):
This comment belongs closer to where the update is happening. core/workspace.js, line 214 at r2 (raw file):
As before, core/workspace.js, line 256 at r2 (raw file):
What is core/workspace.js, line 259 at r2 (raw file):
When would Comments from Reviewable |
|
Review status: 2 of 11 files reviewed at latest revision, 29 unresolved discussions. core/workspace.js, line 289 at r2 (raw file):
You can remove this case. Comments from Reviewable |
|
Review status: 2 of 11 files reviewed at latest revision, 29 unresolved discussions. core/variables.js, line 225 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
In the description of this.name core/variables.js, line 89 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 132 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 211 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 214 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 256 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
It is undefined which still works because creating a variable with an undefined type still sets the type to ''. But to make it more clear, I added an if else statement. core/workspace.js, line 259 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
If we are trying to rename a variable that does not exist. core/workspace.js, line 289 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. Comments from Reviewable |
|
Review status: 1 of 11 files reviewed at latest revision, 21 unresolved discussions. core/variables.js, line 225 at r1 (raw file): Previously, marisaleung wrote…
Interesting. I'd like to discuss that, but I'll move it to the doc. Don't worry about it on this PR. core/variables.js, line 89 at r2 (raw file): Previously, marisaleung wrote…
Return an empty array so that you don't break calling code. core/workspace.js, line 85 at r2 (raw file):
Object.create(null) Comments from Reviewable |
|
Review status: 1 of 11 files reviewed at latest revision, 21 unresolved discussions. core/variables.js, line 89 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. core/workspace.js, line 85 at r2 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Originally I was following javascript style guide rule: But I found this thread that OK's the use of Object.create(null). So this shall be done! Done. Comments from Reviewable |
|
Reviewed 1 of 2 files at r4. Comments from Reviewable |
This CL does the following:
Replaces VariableList with VariableMap.
Edits all workspace.js functions that used VariableList to use VariableMap.
Adds the functions outlined by the Design Doc: createVariable(name, opt_type, opt_id), getVariable(name), getVariableById(id), deleteVariable(name), deleteVariableById(id), renameVariable(oldName, newName), renameVariableById(id, newName), getVariablesOfType(type), getVariableTypes()
Tests that the functionality of every edited function works the same as it did prior to editing.
Tests that the additional functions work at outlined by the Design Doc.
Adjusts any calls made by files outside of workspace that directly or indirectly accessed variableList. The calls are adjusted so that original behavior is preserved.
This change is