Skip to content

Commit 0393741

Browse files
CopilotTechQuery
andauthored
[refactor] objectify HTTPRequest and utility tool functions into Injectable-runtime classes (#23)
Co-authored-by: TechQuery <shiy2008@gmail.com>
1 parent 32f2700 commit 0393741

10 files changed

Lines changed: 822 additions & 620 deletions

File tree

.github/workflows/main.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ on:
33
push:
44
tags:
55
- v*
6+
env:
7+
PUBLISH_TAG: ${{ contains(github.ref_name, '-') && 'next' || 'latest' }}
8+
69
jobs:
7-
Build-and-Publish:
10+
Test-Build-Publish-Deploy:
811
runs-on: ubuntu-latest
912
permissions:
1013
contents: write
@@ -24,11 +27,12 @@ jobs:
2427
run: pnpm i --frozen-lockfile
2528

2629
- name: Build & Publish
27-
run: npm publish --access public --provenance
30+
run: npm publish --access public --provenance --tag ${{ env.PUBLISH_TAG }}
2831
env:
2932
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3033

31-
- name: Update document
34+
- name: Deploy document
35+
if: ${{ env.PUBLISH_TAG == 'latest' }}
3236
uses: peaceiris/actions-gh-pages@v4
3337
with:
3438
publish_dir: ./docs

ReadMe.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,35 @@ npx tsx index.ts
8787

8888
### Non-polyfillable runtimes
8989

90-
1. https://github.com/idea2app/KoAJAX-Taro-adapter
90+
#### Taro (Mini Program, Open Harmony, etc.)
91+
92+
##### 1. Install Polyfill
93+
94+
```shell
95+
npm install event-target-shim taro-fetch-polyfill
96+
```
97+
98+
##### 2. Inject Runtime
99+
100+
Following Example comes from https://github.com/idea2app/Taro-Vant-MobX-ts/blob/70f33be5b2365b8126ed93663905329eae25fbf0/src/store/service.ts
101+
102+
```typescript
103+
import { Event, EventTarget } from 'event-target-shim';
104+
import { defaultHTTPRuntime, HTTPToolkit } from 'koajax';
105+
import { Blob, Headers, ReadableStream, fetch } from 'taro-fetch-polyfill';
106+
107+
const { request } = new HTTPToolkit({
108+
...defaultHTTPRuntime,
109+
Event: Event as typeof globalThis.Event,
110+
EventTarget: EventTarget as typeof globalThis.EventTarget,
111+
Headers,
112+
Blob,
113+
ReadableStream,
114+
fetch: fetch as typeof globalThis.fetch
115+
});
116+
117+
export const httpClient = new HTTPClient({ baseRequest: request });
118+
```
91119

92120
## Example
93121

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koajax",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "HTTP Client based on Koa-like middlewares",

pnpm-lock.yaml

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)