Files
SGF/resources/js/stock-period-request.js
2026-11-04 09:37:20 +02:00

10 lines
572 B
JavaScript

/** 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;};
}