UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

29 lines (27 loc) 664 B
import { atom } from "../../chunks/chunk-OBOPLPUQ.js"; import "../../chunks/chunk-U5RRZUYZ.js"; // src/dashboard/util/KeepPreviousData.ts function keepPreviousData(asynAtom, initalValue) { let expected; const currentAtom = atom(initalValue); return atom( (get, { setSelf }) => { const next = get(asynAtom); const current = get(currentAtom); expected = next.then((value) => { setSelf(expected, value); return value; }); return current ?? expected; }, (get, set, forPromise, value) => { if (forPromise === expected) set(currentAtom, value); } ); } export { keepPreviousData };