Skip to content

Commit

Permalink
fix(plugin): requestConfig with plugins should always get latest co…
Browse files Browse the repository at this point in the history
…nfig from `requestInteceptors`
  • Loading branch information
suhaotian committed Mar 20, 2024
1 parent 9384c86 commit 35af9b7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.2.5 2024/03/20

- fix(plugin): fix `error-retry` plugin default options override bugs
- fix(plugin): `requestConfig` with plugins should always get latest config from `requestInteceptors`

## v0.2.4

Expand Down
8 changes: 4 additions & 4 deletions Mock-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ instance.get('/api/hello').then((res) => {
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/mock.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -79,8 +79,8 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].4/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/mock.umd.js"></script>

<!-- Usage -->
<script>
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ yarn add xior
Use jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -131,7 +131,7 @@ Use jsDelivr CDN:
Use unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -442,9 +442,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/error-retry.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/error-retry.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -457,10 +457,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/error-retry.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/error-retry.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -543,9 +543,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/throttle.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/throttle.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -558,10 +558,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/throttle.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/throttle.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -609,9 +609,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/dedupe.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/dedupe.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -624,10 +624,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/dedupe.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/dedupe.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -685,9 +685,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/error-cache.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/error-cache.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -700,10 +700,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/error-cache.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/error-cache.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -838,9 +838,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/progress.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/progress.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -853,10 +853,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/progress.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/progress.umd.js"></script>

<!-- Usage -->
<script>
Expand Down Expand Up @@ -963,9 +963,9 @@ Use CDN:
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].5/plugins/mock.umd.js"></script>

<!-- Usage -->
<script>
Expand All @@ -978,10 +978,10 @@ Using jsDelivr CDN:
Using unpkg CDN:

```html
<script src="https://unpkg.com/[email protected].4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/dist/xior.umd.js"></script>

<!-- Load plugin -->
<script src="https://unpkg.com/[email protected].4/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/[email protected].5/plugins/mock.umd.js"></script>

<!-- Usage -->
<script>
Expand Down
5 changes: 5 additions & 0 deletions src/xior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ export class xior {
}

async handlerFetch<T>(requestConfig: XiorRequestConfig): Promise<XiorResponse<T>> {
if (this._plugins.length > 0) {
for (const item of this.requestInterceptors.slice(1)) {
requestConfig = await item(requestConfig as XiorInterceptorRequestConfig);
}
}
const {
url,
method,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/tests/plugins/mock/pass_through_on_no_match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('xior mock plguin default instance tests', () => {
]);
});

it('applies interceptors only once', function () {
it('applies interceptors should be twice', function () {
mock.onGet('/get').passThrough();
let requestCount = 0;
let responseCount = 0;
Expand All @@ -113,7 +113,7 @@ describe('xior mock plguin default instance tests', () => {
});

return instance.get('/get').then(function () {
assert.equal(requestCount, 1);
assert.equal(requestCount, 2);
assert.equal(responseCount, 1);
});
});
Expand Down

0 comments on commit 35af9b7

Please sign in to comment.