Skip to content

Commit

Permalink
chore: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
thepassle committed Sep 14, 2023
1 parent d79795a commit 570f834
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 13 additions & 8 deletions packages/ajax/src/Ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ export class Ajax {
this.addRequestInterceptor(createXsrfRequestInterceptor(xsrfCookieName, xsrfHeaderName));
}

const { cacheOptions } = this.__config;
if (cacheOptions.useCache || this.__config.addCaching) {
const { cacheRequestInterceptor, cacheResponseInterceptor } = createCacheInterceptors(
cacheOptions.getCacheIdentifier,
cacheOptions,
);
this.addRequestInterceptor(cacheRequestInterceptor);
this.addResponseInterceptor(cacheResponseInterceptor);
// eslint-disable-next-line prefer-destructuring
const cacheOptions = /** @type {import('@lion/ajax').CacheOptionsWithIdentifier} */ (
this.__config.cacheOptions
);
if ((cacheOptions && cacheOptions.useCache) || this.__config.addCaching) {
if (cacheOptions.getCacheIdentifier) {
const { cacheRequestInterceptor, cacheResponseInterceptor } = createCacheInterceptors(
cacheOptions.getCacheIdentifier,
cacheOptions,
);
this.addRequestInterceptor(cacheRequestInterceptor);
this.addResponseInterceptor(cacheResponseInterceptor);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/ajax/test/Ajax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ describe('Ajax', () => {
// TODO: fix AjaxConfig types => e.g. create FullAjaxConfig with everything "mandatory" and then AjaxConfig (= Partial of it) for user
// @ts-ignore
const ajax1 = new Ajax(config);
const defaultCacheIdentifierFunction = ajax1.options?.cacheOptions?.getCacheIdentifier;

const defaultCacheIdentifierFunction = /** @type {() => void} */ (
ajax1.options?.cacheOptions?.getCacheIdentifier
);
// Then
expect(defaultCacheIdentifierFunction).not.to.be.undefined;
expect(defaultCacheIdentifierFunction).to.be.a('function');
Expand Down

0 comments on commit 570f834

Please sign in to comment.