Skip to content

Commit

Permalink
perf: removed tslib and typed-core in favor of fast-defer
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Dec 8, 2021
1 parent 2215fb9 commit 07ec645
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 56 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"homepage": "https://github.com/ArthurFiorette/axios-cache-interceptor#readme",
"dependencies": {
"@tusbar/cache-control": "^0.6.0",
"tslib": "^2.3.1",
"typed-core": "^2.0.0"
"fast-defer": "^1.1.1"
},
"devDependencies": {
"@arthurfiorette/prettier-config": "*",
Expand Down
4 changes: 2 additions & 2 deletions src/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Method } from 'axios';
import type { Deferred } from 'typed-core/dist/promises/deferred';
import type { Deferred } from 'fast-defer';
import type { HeadersInterpreter } from '../header/types';
import type { AxiosInterceptor } from '../interceptors/types';
import type { AxiosStorage } from '../storage/storage';
Expand Down Expand Up @@ -101,7 +101,7 @@ export interface CacheInstance {
*
* Can be used to listen when a request is cached or not.
*/
waiting: Record<string, Deferred<CachedResponse, void>>;
waiting: Record<string, Deferred<CachedResponse>>;

/**
* The function to parse and interpret response headers. Only used
Expand Down
4 changes: 2 additions & 2 deletions src/interceptors/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AxiosRequestConfig, Method } from 'axios';
import { deferred } from 'typed-core/dist/promises/deferred';
import { deferred } from 'fast-defer';
import type { CacheProperties } from '..';
import type {
AxiosCacheInstance,
Expand Down Expand Up @@ -100,7 +100,7 @@ export class CacheRequestInterceptor<D>

try {
cachedResponse = await deferred;
} catch (e) {
} catch {
// The deferred is rejected when the request that we are waiting rejected cache.
return config;
}
Expand Down
10 changes: 7 additions & 3 deletions src/interceptors/response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { AxiosResponse } from 'axios';
import { extract } from 'typed-core/dist/core/object';
import type { AxiosCacheInstance, CacheAxiosResponse } from '../cache/axios';
import type { CacheProperties } from '../cache/cache';
import type { CachedStorageValue } from '../storage/types';
Expand Down Expand Up @@ -103,7 +102,12 @@ export class CacheResponseInterceptor<R, D>

return cache.data;
})()
: extract(response, ['data', 'headers', 'status', 'statusText']);
: {
data: response.data,
status: response.status,
statusText: response.statusText,
headers: response.headers
};

const newCache: CachedStorageValue = {
state: 'cached',
Expand Down Expand Up @@ -151,7 +155,7 @@ export class CacheResponseInterceptor<R, D>
// Update the cache to empty to prevent infinite loading state
await this.axios.storage.remove(key);
// Reject the deferred if present
this.axios.waiting[key]?.reject();
this.axios.waiting[key]?.reject(null);
delete this.axios.waiting[key];
};

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
"importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
"importsNotUsedAsValues": "error" /* Specify emit/checking behavior for imports that are only used for types */,
"downlevelIteration": true /* Emit more compliant, but verbose and less performant JavaScript for iteration. */,
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
Expand Down
51 changes: 5 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,6 @@
"@typescript-eslint/typescript-estree" "5.6.0"
debug "^4.3.2"

"@typescript-eslint/scope-manager@5.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.5.0.tgz#2b9f3672fa6cddcb4160e7e8b49ef1fd00f83c09"
integrity sha512-0/r656RmRLo7CbN4Mdd+xZyPJ/fPCKhYdU6mnZx+8msAD8nJSP8EyCFkzbd6vNVZzZvWlMYrSNekqGrCBqFQhg==
dependencies:
"@typescript-eslint/types" "5.5.0"
"@typescript-eslint/visitor-keys" "5.5.0"

"@typescript-eslint/scope-manager@5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.6.0.tgz#9dd7f007dc8f3a34cdff6f79f5eaab27ae05157e"
Expand All @@ -731,29 +723,11 @@
"@typescript-eslint/types" "5.6.0"
"@typescript-eslint/visitor-keys" "5.6.0"

"@typescript-eslint/types@5.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.5.0.tgz#fee61ae510e84ed950a53937a2b443e078107003"
integrity sha512-OaYTqkW3GnuHxqsxxJ6KypIKd5Uw7bFiQJZRyNi1jbMJnK3Hc/DR4KwB6KJj6PBRkJJoaNwzMNv9vtTk87JhOg==

"@typescript-eslint/types@5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.6.0.tgz#745cb1b59daadcc1f32f7be95f0f68accf38afdd"
integrity sha512-OIZffked7mXv4mXzWU5MgAEbCf9ecNJBKi+Si6/I9PpTaj+cf2x58h2oHW5/P/yTnPkKaayfjhLvx+crnl5ubA==

"@typescript-eslint/typescript-estree@5.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.5.0.tgz#12f422698c1636bd0206086bbec9844c54625ebc"
integrity sha512-pVn8btYUiYrjonhMAO0yG8lm7RApzy2L4RC7Td/mC/qFkyf6vRbGyZozoA94+w6D2Y2GRqpMoCWcwx/EUOzyoQ==
dependencies:
"@typescript-eslint/types" "5.5.0"
"@typescript-eslint/visitor-keys" "5.5.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/typescript-estree@5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.6.0.tgz#dfbb19c9307fdd81bd9c650c67e8397821d7faf0"
Expand All @@ -767,14 +741,6 @@
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/visitor-keys@5.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.5.0.tgz#4787586897b61f26068a3db5c50b3f5d254f9083"
integrity sha512-4GzJ1kRtsWzHhdM40tv0ZKHNSbkDhF0Woi/TDwVJX6UICwJItvP7ZTXbjTkCdrors7ww0sYe0t+cIKDAJwZ7Kw==
dependencies:
"@typescript-eslint/types" "5.5.0"
eslint-visitor-keys "^3.0.0"

"@typescript-eslint/visitor-keys@5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.6.0.tgz#3e36509e103fe9713d8f035ac977235fd63cb6e6"
Expand Down Expand Up @@ -1606,6 +1572,11 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==

fast-defer@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/fast-defer/-/fast-defer-1.1.1.tgz#9fb1225f1c46515394082b168b797d84b6d0d1da"
integrity sha512-t4JIK/hy9F7J0FaZtnFOzhSteSqOBU11f9HD4BVHwV7TTu/+pfwCX0EjQkt0/ahPbq5NczeQyoN+2YCyWqUCSA==

fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
Expand Down Expand Up @@ -3246,11 +3217,6 @@ tslib@^1.8.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
Expand Down Expand Up @@ -3287,13 +3253,6 @@ type-fest@^0.21.3:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

typed-core@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/typed-core/-/typed-core-2.0.0.tgz#a2db7facfe48126c8eb103f5e2d870964ccdf635"
integrity sha512-P+Apn5jQve1+nUtZ5nmUBviXdy9cxOZ+L8jEo4FhTYczJbhumJxRd885gVqB4bJoFkFUGN1Afd7DF4wMqWMJLA==
dependencies:
tslib "^2.3.1"

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
Expand Down

0 comments on commit 07ec645

Please sign in to comment.