Skip to content

Commit 7253b70

Browse files
author
nebarf
committed
Provider config: allow to supply http cache store in place of http cache
1 parent d51d465 commit 7253b70

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/config/http-client-config-provider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCompareMemo } from '../shared';
33
import { defaultClientProps, defaultHttpReqConfig } from './defaults';
44
import { HttpClientContextProps, HttpClientProviderProps, HttpClientConfig } from './types';
55
import fastCompare from 'react-fast-compare';
6+
import { HttpCacheService } from '..';
67

78
/**
89
* The context to provide the default http client configuration.
@@ -23,7 +24,9 @@ const HttpClientConfigProvider = ({ config, children }: HttpClientProviderProps)
2324
reqOptions: config.reqOptions || defaultHttpReqConfig.reqOptions,
2425
requestBodySerializer:
2526
config.requestBodySerializer || defaultHttpReqConfig.requestBodySerializer,
26-
cache: config.cache || defaultHttpReqConfig.cache,
27+
cache: config.cacheStore
28+
? new HttpCacheService(config.cacheStore)
29+
: defaultHttpReqConfig.cache,
2730
}),
2831
[config],
2932
fastCompare

src/config/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpCacheService } from '../cache';
1+
import { HttpCacheService, HttpCacheStore } from '../cache';
22
import { ReactElement } from 'react';
33
import { HttpRequestOptions, HttpResponseParser } from '../client';
44

@@ -25,7 +25,15 @@ export interface HttpClientContextProps {
2525
config: HttpClientConfig;
2626
}
2727

28+
export interface HttpClientProviderConfig {
29+
reqOptions: Partial<HttpRequestOptions>;
30+
baseUrl: string;
31+
responseParser: HttpResponseParser;
32+
requestBodySerializer: HttpRequestBodySerializer;
33+
cacheStore: HttpCacheStore;
34+
}
35+
2836
export interface HttpClientProviderProps {
2937
children: ReactElement;
30-
config: HttpClientConfig;
38+
config: HttpClientProviderConfig;
3139
}

0 commit comments

Comments
 (0)