react-async-iterators
Version:
The magic of JavaScript async iterators in React ⛓️ 🧬 🔃
31 lines • 1.19 kB
JavaScript
import { reactAsyncIterSpecialInfoSymbol, parseReactAsyncIterable, } from '../common/ReactAsyncIterable.js';
import { asyncIterSyncMap } from '../common/asyncIterSyncMap.js';
import { isAsyncIter } from '../common/isAsyncIter.js';
export { iterateFormatted };
function iterateFormatted(source, formatFn) {
if (!isAsyncIter(source)) {
return formatFn(source, 0);
}
const { baseIter, formatFn: precedingFormatFn } = parseReactAsyncIterable(source);
return {
[Symbol.asyncIterator]: () => asyncIterSyncMap(source, formatFn)[Symbol.asyncIterator](),
get value() {
return !source.value
? undefined
: {
get current() {
const result = precedingFormatFn(source.value.current, 0);
return formatFn(result, 0);
},
};
},
[reactAsyncIterSpecialInfoSymbol]: {
origSource: baseIter,
formatFn: (value, i) => {
const result = precedingFormatFn(value, i);
return formatFn(result, i);
},
},
};
}
//# sourceMappingURL=index.js.map