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
Problem
compute(assetFilter)takes a parameter but ignores it, reading the globaltradesdirectly (src/js/05-compute.jsline 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 (swapwindow.trades, call compute, swap back in a finally block). This is a 111-line workaround for a missing seam.Deletion test: If you deleted
mergeOpenLotsand just passed trades to compute, the workaround disappears and the real logic shrinks to ~10 lines.Files involved
src/js/05-compute.jssrc/js/05a-merge-open-lots.jsProposed solution
Give
compute(trades, assetFilter)an explicittradesparameter.mergeOpenLotscollapses to a pure transform with no global swap needed.Benefits
mergeOpenLotsbecomes testable in isolationCategory
Deepening opportunity — architecture review