From 71879f81b10ae8bfcb1d4dabbf04be9989af6ed3 Mon Sep 17 00:00:00 2001 From: rizky Date: Thu, 5 Sep 2024 18:04:46 -0700 Subject: [PATCH] bulk-query --- comps/custom/QrLabel.tsx | 0 comps/custom/QrReader.tsx | 0 exports.tsx | 5 ++--- utils/bulk-query.ts | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) mode change 100644 => 100755 comps/custom/QrLabel.tsx mode change 100644 => 100755 comps/custom/QrReader.tsx create mode 100755 utils/bulk-query.ts diff --git a/comps/custom/QrLabel.tsx b/comps/custom/QrLabel.tsx old mode 100644 new mode 100755 diff --git a/comps/custom/QrReader.tsx b/comps/custom/QrReader.tsx old mode 100644 new mode 100755 diff --git a/exports.tsx b/exports.tsx index 3794f6f..d01d17c 100755 --- a/exports.tsx +++ b/exports.tsx @@ -15,7 +15,6 @@ export const Dialog = lazify( async () => (await import("@/comps/ui/dialog")).Dialog ); - export const Typeahead = lazify( async () => (await import("@/comps/ui/typeahead")).Typeahead ); @@ -106,7 +105,7 @@ export const Import = lazify( export const Sheet = lazify( async () => (await import("@/comps/sheet/sheet")).SheetCn ); -export {formatBytes} from "@/comps/import/lib/formatBytes" +export { formatBytes } from "@/comps/import/lib/formatBytes"; export { fetchLinkParams } from "@/comps/form/field/type/TypeLink"; export { FieldLoading, Spinner } from "@/comps/ui/field-loading"; export { lang } from "lib/lang"; @@ -121,7 +120,7 @@ export { toast, Toaster } from "./comps/ui/toast"; export { NavLink } from "./comps/popup/NavLink"; export { kvToJSON } from "./utils/kv-to-json"; export { overrideNav } from "./utils/override-nav"; - +export { bulk_query } from "./utils/bulk-query"; export const _sum = sum; export const _get = __get; diff --git a/utils/bulk-query.ts b/utils/bulk-query.ts new file mode 100755 index 0000000..9d97f79 --- /dev/null +++ b/utils/bulk-query.ts @@ -0,0 +1,18 @@ +export const bulk_query = async ({ + list, + task, +}: { + list: any[]; + task: (e: any, index?: number) => Promise; +}) => { + const recursive = async (data: any, list: Array, index: number) => { + if (list.length) { + await task(data, index); + index++; + if (index <= list.length - 1) { + await recursive(list[index], list, index); + } + } + }; + await recursive(list[0], list, 0); +};