Skip to content

Commit eae0574

Browse files
committed
feat(rescript-react-fetch): binding for react-fetch
1 parent 5de7582 commit eae0574

File tree

12 files changed

+155
-1
lines changed

12 files changed

+155
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ temp/
156156
### Reasonml ###
157157
/lib
158158

159+
**/.DS_Store

examples/bsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@ri7nz/rescript-intersection-observer",
1717
"@ri7nz/rescript-dom",
1818
"rescript-abort-controller",
19+
"rescript-react-fetch",
1920
"bs-webapi"
2021
]
2122
}

examples/dev/dev__reactfetch.js

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

examples/dev/dev__reactfetch.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
Write Test for Reactfetch
3+
r*/
4+
5+
let url = "https://api.github.com/v3/user/ri7nz"
6+
7+
let data = url->ReactFetch.fetch->ReactFetch.json
8+
9+
let _ = url->ReactFetch.preload

examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@ri7nz/rescript-dom": "link:../rescript-dom",
1414
"@ri7nz/rescript-intersection-observer": "link:../rescript-intersection-observer",
1515
"bs-webapi": "^0.19.1",
16-
"rescript-abort-controller": "link:../rescript-abort-controller"
16+
"rescript-abort-controller": "link:../rescript-abort-controller",
17+
"rescript-react-fetch": "link:../rescript-react-fetch"
1718
}
1819
}

examples/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ bs-webapi@^0.19.1:
3131
version "0.0.0"
3232
uid ""
3333

34+
"rescript-react-fetch@link:../rescript-react-fetch":
35+
version "0.0.0"
36+
uid ""
37+
3438
rescript@9.1.1:
3539
version "9.1.1"
3640
resolved "https://registry.yarnpkg.com/rescript/-/rescript-9.1.1.tgz#de2eb5470a463d7eea493b59537d49bafa6bc5e9"

rescript-react-fetch/CHANGELOG.md

Whitespace-only changes.

rescript-react-fetch/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# rescript-react-fetch
2+
> Zero-cost binding for [`react-fetch`](https://github.com/facebook/react/blob/main/packages/react-fetch)
3+
4+
## Installation
5+
6+
Run the following in your favorit console:
7+
8+
> Don't forget install peer-dependencies `react-fetch`
9+
10+
```console
11+
> yarn add rescript-react-fetch
12+
```
13+
14+
**OR**
15+
16+
```console
17+
> npm install --save rescript-react-fetch
18+
19+
```
20+
21+
Then, add `rescript-react-fetch` in your `bsconfig.json`:
22+
```diff
23+
-- "bs-dependencies": [],
24+
++ "bs-dependencies": [rescript-react-fetch],
25+
```
26+
27+
## Usage
28+
29+
```rescript
30+
let url = "https://api.github.com/v3/user/ri7nz"
31+
32+
let data = url->ReactFetch.fetch->ReactFetch.json
33+
34+
let _ = url->ReactFetch.preload
35+
```
36+
37+
Or you can check this [**Example: dev__reactfetch**](https://github.com/ri7nz/rescript-libs/tree/main/examples/dev/dev__reactfetch.res).
38+
39+
## API
40+
> `react-fetch` current state is **UNSTABLE**, current API maybe changes!
41+
42+
### ReactFetch.fetch(string)
43+
* **Return** `response`
44+
### ReactFetch.preload(string)
45+
* **Return** `unit`
46+
### ReactFetch.json(response)
47+
* **Return** `Js.Json.t`
48+
### ReactFetch.arrayBuffer(response)
49+
* **Return** `Js.TypedArray2.ArrayBuffer.t`
50+
### ReactFetch.text(response)
51+
* **Return** `string`

rescript-react-fetch/bsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "rescript-react-fetch",
3+
"sources": {
4+
"dir": "src",
5+
"subdirs": true
6+
},
7+
"package-specs": {
8+
"module": "es6",
9+
"in-source": true
10+
}
11+
}

rescript-react-fetch/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "rescript-react-fetch",
3+
"version": "0.0.0",
4+
"description": "(experimental 🚧) Zero-cost binding for react-fetch",
5+
"author": "ri7nz <hi@rin.rocks>",
6+
"license": "MIT",
7+
"keywords": [
8+
"ReScript",
9+
"ReasonML",
10+
"React",
11+
"ReactFetch",
12+
"ReactServer"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/ri7nz/rescript-libs.git",
17+
"directory": "rescript-react-fetch"
18+
},
19+
"bugs": "https://github.com/ri7nz/rescript-libs/issues",
20+
"scripts": {
21+
"start": "rescript build -w",
22+
"build": "rescript build -with-deps",
23+
"clean": "rescript clean"
24+
},
25+
"publishConfig": {
26+
"access": "public"
27+
},
28+
"devDependencies": {
29+
"rescript": "9.1.1"
30+
},
31+
"peerDependencies": {
32+
"react-fetch": ">=0.0.0"
33+
}
34+
}

0 commit comments

Comments
 (0)