mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
디렉터리 페이지에서의 네트워크 호출 최적화
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from "./format";
|
||||
export * from "./gotoStateful";
|
||||
export * from "./promise";
|
||||
export * from "./sort";
|
||||
|
||||
16
src/lib/utils/promise.ts
Normal file
16
src/lib/utils/promise.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const monotonicResolve = <T>(
|
||||
promises: (Promise<T | undefined> | false)[],
|
||||
callback: (value: T) => void,
|
||||
) => {
|
||||
let latestResolvedIndex = -1;
|
||||
|
||||
promises.forEach((promise, index) => {
|
||||
if (!promise) return;
|
||||
promise.then((value) => {
|
||||
if (value !== undefined && index > latestResolvedIndex) {
|
||||
latestResolvedIndex = index;
|
||||
callback(value);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -32,7 +32,7 @@ const sortByDateAsc: SortFunc = ({ date: a }, { date: b }) => {
|
||||
|
||||
const sortByDateDesc: SortFunc = (a, b) => -sortByDateAsc(a, b);
|
||||
|
||||
export const sortEntries = <T extends SortEntry>(entries: T[], sortBy: SortBy) => {
|
||||
export const sortEntries = <T extends SortEntry>(entries: T[], sortBy = SortBy.NAME_ASC) => {
|
||||
let sortFunc: SortFunc;
|
||||
|
||||
switch (sortBy) {
|
||||
@@ -54,4 +54,5 @@ export const sortEntries = <T extends SortEntry>(entries: T[], sortBy: SortBy) =
|
||||
}
|
||||
|
||||
entries.sort(sortFunc);
|
||||
return entries;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user