/** One cancellable read: a late response cannot replace another period or context. */ export function requestStockPeriod({query,api,data,error,loading}) { let cancelled=false; data(null);error('');loading(true); const params=new URLSearchParams(Object.entries(query).filter(([,value])=>value!==undefined&&value!=='')); Promise.resolve().then(()=>api('/api/stock-read?'+params)).then(value=>{if(!cancelled)data(value);}) .catch(e=>{if(!cancelled)error(e.message);}).finally(()=>{if(!cancelled)loading(false);}); return ()=>{cancelled=true;}; }