Page MenuHomeWildfire Games

Add scopes to the options page and use let
AbandonedPublic

Authored by elexis on May 16 2017, 5:59 PM.

Details

Reviewers
Polakrity
Summary

The option page initializes the GUI elements in a big switch statement in setupControl and has some helper variable in each case of the switch.
Since these helper variables are only valid for the specific case, they should become inaccessible to the other cases of the switch statement to prevent accidental overwrites and
thereby making it quicker to review.

Test Plan

Convince yourself that these variables changed are only referenced in that specific switch case.

Diff Detail

Repository
rP 0 A.D. Public Repository
Branch
/ps/trunk
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 1768
Build 2799: Vulcan BuildJenkins
Build 2798: arc lint + arc unit

Event Timeline

elexis created this revision.May 16 2017, 5:59 PM
Vulcan added a subscriber: Vulcan.May 16 2017, 7:42 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1232/ for more details.

Polakrity edited edge metadata.May 16 2017, 11:34 PM

You made a mistake that broke the slider case.

binaries/data/mods/public/gui/options/options.js
71

Use an unique variable declaration for get the "user" value instead to declare each time a new variable.

164

This is onValueChange that is used for slider.

elexis marked an inline comment as done.May 17 2017, 3:02 AM

Moving the config value out of the switch isn't really nice, since in one case we convert it to boolean, in others to a number, so nothing really gained. The idea was to remove occurances out of the inner scope as far as possible.

Following this, I ended up rewriting the entire file :(

Patch:

options.js:

Would like to know if there is opposition to the changes before spending more time on it. Won't be trivial to review.

This rewriting seems cleaner/better coding style than the actual code.
Object literals increase readability and maintainability in this case.

Maybe edit the title of revision and add the proposal patch in summary for get more reviews.

elexis planned changes to this revision.May 19 2017, 12:10 PM

Thanks for the feedback. The only drawback of removing the loops is not checking for unknown properties. On the other hand we don't have validation for all the other JSON files we have around. I won't have time to focus on this before the next release though (really low priority since there is no real gain besides a bit of readability)

elexis abandoned this revision.Sep 2 2017, 12:36 AM

Polakrity, thanks for your feedback. It has given me the courage to cleanup the page slightly remove the workarounds in rP20010, rP20066, rP20091, rP20092 and
then rewrite the entire thing to remove any duplication seen in the JS code and XML file in D805. I hope to get to your patches soon!