Skip to content

Architecture: make compute() take explicit trades parameter to eliminate global swap in mergeOpenLots #72

@heyitsStylez

Description

@heyitsStylez

Problem

compute(assetFilter) takes a parameter but ignores it, reading the global trades directly (src/js/05-compute.js line 17). Because compute can't accept trades as input, mergeOpenLots — which needs to compute on a hypothetical modified trade array — must temporarily swap the global (swap window.trades, call compute, swap back in a finally block). This is a 111-line workaround for a missing seam.

Deletion test: If you deleted mergeOpenLots and just passed trades to compute, the workaround disappears and the real logic shrinks to ~10 lines.

Files involved

  • src/js/05-compute.js
  • src/js/05a-merge-open-lots.js

Proposed solution

Give compute(trades, assetFilter) an explicit trades parameter. mergeOpenLots collapses to a pure transform with no global swap needed.

Benefits

  • mergeOpenLots becomes testable in isolation
  • The compute module's interface reflects what it actually needs
  • Every caller knows exactly what state compute depends on
  • The global-swap pattern (a known source of subtle bugs) is eliminated

Category

Deepening opportunity — architecture review

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageMaintainer needs to evaluate this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions