Super simple "deduplicate" implementation, inspire by useSWR.
Please fork the repo if u want use it.
It realy a super basic implementation, feel free to just copy the code an make more complexe features according to yours needs.
Warning
This repo will probabely not be maintained
You can find an exemple in exemples/html/src/main.ts.
const fetcher = () => fetch('url').then(res => res.json())
const { data, error } = await deduplicate('identifier', fetcher, 1000)
identifier: must be a string, the key use for store result in cachefetcher: a async function, must return the data (store in cache) or throw an errortime: duration (in milliseconds) during data is store in cache, by default is2000
An object with properties data and error.
data: the return offetcherorundefinediffetcherthrow an errorerror:falseif no error, or the error throw byfetcher