Skip to content

Commit

Permalink
feat: add pendingLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 28, 2022
1 parent 827908e commit 055bc3c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/data-fetching/defineLoader.ts
Expand Up @@ -116,6 +116,7 @@ export function defineLoader<P extends Promise<any>, isLazy extends boolean>(
error,
refresh,
invalidate,
pendingLoad,
}

return Object.assign(commonData, data)
Expand All @@ -126,6 +127,8 @@ export function defineLoader<P extends Promise<any>, isLazy extends boolean>(
let pendingPromise: Promise<void> | undefined | null
let currentNavigation: RouteLocationNormalizedLoaded | undefined | null

const pendingLoad = () => pendingPromise

function load(route: RouteLocationNormalizedLoaded, router: Router) {
let entry = cache.get(router)
const { lazy } = options
Expand Down Expand Up @@ -329,6 +332,11 @@ export interface _DataLoaderResult {
* Invalidates the data so it is reloaded on the next request.
*/
invalidate: () => void

/**
* Get the promise of the current loader if there is one, returns a falsy value otherwise.
*/
pendingLoad: () => Promise<void> | undefined | null
}

export interface _DataLoaderResultLazy<T> extends _DataLoaderResult {
Expand Down

0 comments on commit 055bc3c

Please sign in to comment.