Skip to content

Commit

Permalink
feat: support forever-loading CustomDataProvider (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee authored May 27, 2019
1 parent 64b6fe5 commit e80c7b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions services/data/src/context/makeCustomContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface CustomContextData {
[resourceName: string]: CustomResource
}
export type CustomContextOptions = {
loadForever?: boolean
failOnMiss?: boolean
}

Expand Down Expand Up @@ -54,7 +55,7 @@ const resolveCustomResource = async (

export const makeCustomContext = (
customData: CustomContextData,
{ failOnMiss = true }: CustomContextOptions = {}
{ failOnMiss = true, loadForever = false }: CustomContextOptions = {}
): ContextType => {
const apiUrl = joinPath(baseUrl, 'api', String(apiVersion))
const customFetch: FetchFunction = async query => {
Expand All @@ -72,11 +73,14 @@ export const makeCustomContext = (
failOnMiss,
})
}
const foreverLoadingFetch: FetchFunction = async query => {
return new Promise(() => {}) // Load forever
}
const context = {
baseUrl,
apiVersion,
apiUrl,
fetch: customFetch,
fetch: loadForever ? foreverLoadingFetch : customFetch,
}
return context
}

0 comments on commit e80c7b7

Please sign in to comment.