thegreenwebfoundation / co2.js

An npm module for accessing the green web API, and estimating the carbon emissions from using digital services
Other
385 stars 48 forks source link

Store segment flag on CO2 instance, not models #158

Closed EvanHahn closed 1 year ago

EvanHahn commented 1 year ago

No user impact is expected from this change.

Background: you can ask CO2 to return segmented results by setting the results option to "segment". The CO2 instance stores this flag for later.

This changes where that flag is stored. Previously, it was stored as a public property of each model. This was unused by the model and is an unnecessary mutation.

Now, the property is stored on the CO2 instance. I believe this is easier to follow. It should also make it possible to turn the models from stateful classes into stateless objects, simplifying the code (an idea that was discussed years ago).

This new flag is explicitly marked private with the @private JSDoc tag and implicitly marked private by prefixing its name with an underscore; a common JS convention. (I considered using private class fields instead, but browser support is new enough that this seemed risky.)

fershad commented 1 year ago

This change will be released with the next update for data, early August 2023.