Skip to content

Make scale-reference stateless: settings per call, no global config - #2

Merged
YauhenBichel merged 1 commit into
mainfrom
refactor/stateless
Sep 13, 2026
Merged

YauhenBichel merged 1 commit into
mainfrom
refactor/stateless

Conversation

@YauhenBichel

Copy link
Copy Markdown
Member

The package kept one shared, changeable settings object: configure() changed it for every caller in the app, and resetConfig() put it back. This PR removes that. Every setting is now passed with the call, and the package keeps no state at all.

What changes

Before After
configure({maxTiltDegrees, minReferencePixels, references}) changed module state for everyone fromEllipse(ellipse, diameterMm, options?). The options apply to that call only.
getConfig() / resetConfig() Removed. DEFAULT_OPTIONS is a frozen constant.
REFERENCES, MAX_TILT_DEGREES, MIN_REFERENCE_PIXELS were getters over the shared object The same names are plain frozen constants.
A mistyped option (maxTilt) was silently ignored An unknown or non-positive option throws a TypeError.
explain(reason) had fixed English text explain(reason, messages?) accepts your own text or translation, with default as a fallback.

The reference table (DEFAULT_REFERENCES) stays as a frozen, published-size constant. Nothing reads it for you; fromEllipse takes any diameter, so apps keep their own references.

The version goes to 0.2.0 because the removed configure, getConfig and resetConfig break the old API. Nothing is published yet. The MoleCare app never calls them: its adapter only re-exports them, and it will be updated when the pin is bumped. The app's own ScaleReference test (17 cases) passes unchanged against this code.

How it was checked

  • 25 tests (was 19). All 7 new or changed tests fail on the old code.
  • One test fails if any source file declares a module-level let or var, so state cannot creep back in.
  • Tarball: 7 files, all expected.
  • README and CONTRIBUTING now describe the stateless design.

🤖 Generated with Claude Code

Remove the shared settings object (configure/getConfig/resetConfig).
Settings are passed per call: fromEllipse(ellipse, diameterMm, options),
explain(reason, messages). Defaults are frozen constants; an unknown or
non-positive option throws. A test fails on any module-level let/var.
Version 0.2.0 (breaking; nothing published yet).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@YauhenBichel
YauhenBichel merged commit e3ca2be into main Sep 13, 2026
3 checks passed
@YauhenBichel
YauhenBichel deleted the refactor/stateless branch September 13, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant