kirkmcdonald.github.io icon indicating copy to clipboard operation
kirkmcdonald.github.io copied to clipboard

Refactor to more modern version of JavaScript

Open KirkMcDonald opened this issue 5 years ago • 3 comments

When I started this project in 2015, ECMAScript 2015 had only just been specified, and browser support for it was still some time off. This means that the calculator is written in what is now a fairly archaic dialect of JavaScript, and I believe the code base could be significantly improved by taking advantage of a number of features which have become supported by browsers since the project's inception.

Modules

The current overall organization of the calculator is completely woeful. calc.html includes the whole mess of .js source files in a mostly (but not entirely!) arbitrary order. Many pieces of state are kept in global variables. All of the code's defined names just live in this undifferentiated soup of globals.

Refactoring the code to use modules should improve matters significantly. The main difficulty with this will be encapsulating all of the existing global state into a form that may be shared in a more structured manner.

Classes

The calculator makes heavy use of old-style JS prototypes, in a way that is meant to emulate classes. Refactoring this code to use actual classes will probably be an improvement.

for/of loops

These are just pretty good, and should simplify a number of the loops throughout the code.

KirkMcDonald avatar Mar 18 '19 23:03 KirkMcDonald

I recently put together a calculator for the game Satisfactory, in large part as a case study in redesigning the calculator both in ES6 and to make heavy use of d3. The results are very encouraging.

KirkMcDonald avatar Apr 02 '19 08:04 KirkMcDonald

Hey, @KirkMcDonald. I've been working on a TypeScript port of Factorio Calculator which addresses a lot of the things outlined here. I still have a lot of cleaning up to do, for instance, resolving some of the global variables and converting more of the for loops, but it builds and runs (so far as I have tested) exactly as the original. If you'd like to collaborate on it, just let me know. Thanks for the awesome calculator. :)

acid1103 avatar Jun 18 '19 17:06 acid1103

I would also be interested in helping with a TS port.

I would also be interested in a React/Redux port, as this has gained a lot of traction in the development community and could help make the codebase more robust to having additional devs.

jollygreenlaser avatar Oct 24 '19 21:10 jollygreenlaser