Skip to content

Commit d7f14d1

Browse files
authored
Add support for keepalive (#29)
1 parent b4ffc0b commit d7f14d1

File tree

13 files changed

+54
-44
lines changed

13 files changed

+54
-44
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ Alias:
291291
Params:
292292

293293
- `options` object or string (will be used as `uri`)
294-
- `body` default=`null`
294+
- `body` default=`undefined`
295+
- `keepalive` default=`false`
295296
- `method` default=`'GET'`
296297
- `headers` default=`{}`
297298
- `params` default=`{}`

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "6.0.0-alpha.4"
5+
"version": "6.0.0-alpha.5"
66
}

packages/tinhte-api-demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinhte-api-demo",
3-
"version": "6.0.0-alpha.4",
3+
"version": "6.0.0-alpha.5",
44
"description": "tinhte-api DEMO",
55
"private": true,
66
"scripts": {
@@ -18,7 +18,7 @@
1818
"react-dom": "^16.9.0",
1919
"react-router-dom": "^5.0.1",
2020
"sanitize-html": "^2.3.3",
21-
"tinhte-api-react": "^6.0.0-alpha.4"
21+
"tinhte-api-react": "^6.0.0-alpha.5"
2222
},
2323
"devDependencies": {
2424
"standard": "^14.3.1"

packages/tinhte-api-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinhte-api-react",
3-
"version": "6.0.0-alpha.4",
3+
"version": "6.0.0-alpha.5",
44
"description": "tinhte-api React component",
55
"main": "dist/tinhte-api-react.cjs.js",
66
"module": "dist/tinhte-api-react.js",
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"js-cookie": "^2.2.1",
2121
"react-ssr-prepass": "^1.2.1",
22-
"tinhte-api": "^6.0.0-alpha.3"
22+
"tinhte-api": "^6.0.0-alpha.5"
2323
},
2424
"peerDependencies": {
2525
"react": ">=16.8 <17"

packages/tinhte-api-react/src/helpers/fetchApiDataForProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ export async function fetchApiDataForProvider (api: ReactApi, internalApi: React
2525

2626
const json = await api.fetchMultiple(() => {
2727
for (let i = 0; i < queue.length; i++) {
28+
const uniqueId = standardizeReqOptions(fetch as any)
29+
if (uniqueId === undefined) {
30+
continue
31+
}
32+
2833
api.fetchOne(queue[i])
2934
.catch((reason) => {
30-
const uniqueId = standardizeReqOptions(fetch as any)
3135
internalApi.log('fetchApiDataForProvider queue[%d] has been rejected (%s, %s)', i, uniqueId, reason)
3236
reasons[uniqueId] = reason instanceof Error ? reason.message : typeof reason === 'string' ? reason : JSON.stringify(reason)
3337
})

packages/tinhte-api-react/src/hoc/ApiConsumer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ const useApiData = (props: _ApiConsumerPropsInternal, fetches?: Record<string, R
5959
}
6060

6161
const uniqueId = standardizeReqOptions(fetch as any)
62+
if (uniqueId === undefined) {
63+
continue
64+
}
65+
6266
const job = jobs[uniqueId]
6367
if (job === undefined ||
6468
job._req === undefined ||

packages/tinhte-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinhte-api",
3-
"version": "6.0.0-alpha.3",
3+
"version": "6.0.0-alpha.5",
44
"description": "tinhte-api library",
55
"main": "dist/tinhte-api.cjs.js",
66
"module": "dist/tinhte-api.js",

packages/tinhte-api/src/fetches/batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StandardizedFetchOptions } from '../helpers/standardizeReqOptions'
1+
import { StandardizedFetchOptions } from './types'
22

33
export interface Batch {
44
enqueue: (resolve: BatchResolve, reject: BatchReject) => void

packages/tinhte-api/src/fetches/fetchMultiple.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import errors from '../helpers/errors'
2-
import standardizeReqOptions, { StandardizedFetchOptions } from '../helpers/standardizeReqOptions'
2+
import standardizeReqOptions from '../helpers/standardizeReqOptions'
33
import { ApiInternal } from '../types'
44
import { Batches, BatchReject, BatchRequest, BatchResolve } from './batch'
5-
import { FetchHeaders, FetchJson, FetchMultiple, FetchMultipleJob, FetchMultipleJobs, FetchMultipleOptions, FetchParams } from './types'
5+
import { FetchHeaders, FetchJson, FetchMultiple, FetchMultipleJob, FetchMultipleJobs, FetchMultipleOptions, FetchParams, StandardizedFetchOptions } from './types'
66

77
interface _Context {
88
batchHeaders: FetchHeaders

packages/tinhte-api/src/fetches/fetchOne.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import standardizeReqOptions, { StandardizedFetchOptions } from '../helpers/standardizeReqOptions'
1+
import standardizeReqOptions from '../helpers/standardizeReqOptions'
22
import { ApiInternal } from '../types'
33
import { Batches } from './batch'
4-
import { FetchJson, FetchOne } from './types'
4+
import { FetchJson, FetchOne, StandardizedFetchOptions } from './types'
55

66
const fetchOneInit = (fetchJson: FetchJson, batch: Batches, internalApi: ApiInternal): FetchOne => {
77
let reqLatestId = 0
@@ -20,7 +20,7 @@ const fetchOneInit = (fetchJson: FetchJson, batch: Batches, internalApi: ApiInte
2020
const reqId = reqLatestId
2121
const current = batch.getCurrent()
2222

23-
if (current === null || options.body !== null || !options.parseJson) {
23+
if (current === null || uniqueId === undefined) {
2424
internalApi.log('Request #%d is being fetched...', reqId)
2525
return await fetchJson(options)
2626
} else {

0 commit comments

Comments
 (0)