Refactoring BreezeMap, an adventure in ES6+
: Deniz Aydin
Minutes: 2185
- We now have classes instead of functions pretending to be classes (the way it used to be done).
- These classes have fields and methods. Some fields/methods are static, depending on the usage requirements (i.e. if we need to be able to call a method on a class without having to instantiate it, the method needs to be staticized).
- By extension, everything in
util.js
is static because of their usage invectorlayer.js
. The fields are declared in a static block as well. Note that the fields that go inside a static block need to be declared before their assignment in the block. - Organized code into 3 reusable modules for better structure.
- The original
hcmc_ol.js
has been split into aconstants.js
, autil.js
, and avectorlayer.js
. Each of these is a module. - The build currently does not have a minify option. ESBuild can probably take care of this, but that might take some doing now that the library has been split into three files.
- Lots of globally-scoped variables (i.e. vars) have been turned into let statements.
- Some return types were incorrect. Those have been fixed.
- Function signatures have been made to be less verbose.
- The classes need to be exported at the end of the file to be able to be imported into other files.
- Imports work out of the box; imports into the HTML files where these classes are used require a source type declaration of module instead of ecmascript, and the file needs to be imported explicitly in the HTML inline JavaScript bit.