Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 106x 8x 24x 24x 44x | import { PackageCheck } from "shared-utils";
import { getItem } from "@/api/useGetItem";
import { DataPoller } from "./DataPoller";
export type CheckDocumentFunction = (
check: ReturnType<typeof PackageCheck> & { recordExists: boolean },
) => boolean;
type DocumentPollerOptions = {
includeDraft?: boolean;
};
export const documentPoller = (
id: string,
documentChecker: CheckDocumentFunction,
options?: DocumentPollerOptions,
) =>
new DataPoller({
interval: 1000,
pollAttempts: 20,
onPoll: (data) => {
const check = PackageCheck(data._source);
return documentChecker({ ...check, recordExists: !!data });
},
fetcher: () => getItem(id, { includeDraft: options?.includeDraft }),
});
|