Skip to content

Commit ca9a1b8

Browse files
committed
Initial commit
1 parent 0a4bca4 commit ca9a1b8

9 files changed

Lines changed: 243 additions & 209 deletions

File tree

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
## useQuery(...) ✅
2+
3+
### Result
4+
5+
- [x] `status: String`
6+
- [x] `isIdle: boolean`
7+
- [x] `isLoading: boolean`
8+
- [x] `isSuccess: boolean`
9+
- [x] `isError: boolean`
10+
- [x] `isLoadingError: boolean`
11+
- [x] `isRefetchError: boolean`
12+
- [x] `data: TData`
13+
- [x] `dataUpdatedAt: number`
14+
- [x] `error: null | TError`
15+
- [x] `errorUpdatedAt: number`
16+
- [x] `isStale: boolean`
17+
- [x] `isPlaceholderData: boolean`
18+
- [x] `isPreviousData: boolean`
19+
- [x] `isFetched: boolean`
20+
- [x] `isFetchedAfterMount: boolean`
21+
- [x] `isFetching: boolean`
22+
- [x] `failureCount: number`
23+
- [x] `refetch: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise<UseQueryResult>`
24+
- [x] `remove: () => void`
25+
26+
### Options
27+
28+
- [x] `queryKey: string | unknown[]`
29+
- [x] `queryFn: (context: QueryFunctionContext) => Promise<TData>`
30+
- [x] `enabled: boolean`
31+
- [x] `retry: boolean | number | (failureCount: number, error: TError) => boolean`
32+
- [x] `retryOnMount: boolean`
33+
- [x] `retryDelay: number | (retryAttempt: number, error: TError) => number`
34+
- [x] `staleTime: number | Infinity`
35+
- [x] `cacheTime: number | Infinity`
36+
- [x] `queryKeyHashFn: (queryKey: QueryKey) => string`
37+
- [x] `refetchInterval: false | number`
38+
- [x] `refetchIntervalInBackground: boolean`
39+
- [x] `refetchOnMount: boolean | "always"`
40+
- [x] `refetchOnWindowFocus: boolean | "always"`
41+
- [x] `refetchOnReconnect: boolean | "always"`
42+
- [x] `notifyOnChangeProps: string[] | "tracked"`
43+
- [x] `notifyOnChangePropsExclusions: string[]`
44+
- [x] `onSuccess: (data: TData) => void`
45+
- [x] `onError: (error: TError) => void`
46+
- [x] `onSettled: (data?: TData, error?: TError) => void`
47+
- [x] `select: (data: TData) => unknown`
48+
- [x] `suspense: boolean`
49+
- [x] `initialData: TData | () => TData`
50+
- [x] `initialDataUpdatedAt: number | (() => number | undefined)`
51+
- [x] `placeholderData: TData | () => TData`
52+
- [x] `keepPreviousData: boolean`
53+
- [x] `structuralSharing: boolean`
54+
- [x] `useErrorBoundary: boolean`
55+
56+
## useQueries(...) ✅
57+
58+
## Features
59+
60+
- useQuery ✅
61+
- useQueries ✅
62+
- useInfiniteQuery
63+
- useMutation
64+
- useIsFetching
65+
- useIsMutating
66+
- QueryClient
67+
- QueryClientProvider
68+
- useQueryClient
69+
- QueryCache
70+
- MutationCache
71+
- QueryObserver
72+
- InfiniteQueryObserver
73+
- QueriesObserver
74+
- QueryErrorResetBoundary
75+
- useQueryErrorResetBoundary
76+
- focusManager
77+
- onlineManager
78+
- setLogger
79+
- hydration/Hydrate
80+
- hydration/useHydrate
81+
- hydration/hydrate
82+
- hydration/dehydrate

examples/README.md

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1 @@
1-
# Getting Started with Create React App
21

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4-
5-
## Available Scripts
6-
7-
In the project directory, you can run:
8-
9-
### `yarn start`
10-
11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13-
14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
16-
17-
### `yarn test`
18-
19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `yarn build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `yarn eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35-
36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37-
38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39-
40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41-
42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
47-
48-
### Code Splitting
49-
50-
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51-
52-
### Analyzing the Bundle Size
53-
54-
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55-
56-
### Making a Progressive Web App
57-
58-
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59-
60-
### Advanced Configuration
61-
62-
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63-
64-
### Deployment
65-
66-
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67-
68-
### `yarn build` fails to minify
69-
70-
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

examples/bsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
}
1515
],
1616
"suffix": ".bs.js",
17-
"bs-dependencies": ["@rescript/react", "bs-fetch", "decco"],
18-
"ppx-flags": ["decco/ppx"]
17+
"bs-dependencies": ["@rescript/react", "bs-fetch", "@glennsl/bs-json"],
18+
"ppx-flags": []
1919
}

examples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@glennsl/bs-json": "5.0.2",
67
"@rescript/react": "0.10.2",
78
"@testing-library/jest-dom": "^5.11.4",
89
"@testing-library/react": "^11.1.0",

examples/src/App.res

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
module Promise = Js.Promise
22

3-
@decco
4-
type todo = {title: string}
3+
type todo = {
4+
completed: bool,
5+
id: int,
6+
title: string,
7+
userId: int,
8+
}
59

6-
module TodoQuery = ReactQuery.Query.Make({
7-
type queryKey = string
8-
type data = todo
9-
type error = string
10-
type decodeError = Decco.decodeError
11-
let decoder = todo_decode
12-
})
10+
module Decode = {
11+
open Json.Decode
12+
let todo = json => {
13+
completed: field("completed", bool, json),
14+
id: field("id", int, json),
15+
title: field("title", string, json),
16+
userId: field("userId", int, json),
17+
}
18+
}
1319

14-
let fetchTodo = _ =>
15-
Fetch.fetch("https://jsonplaceholder.typicode.com/todos/1") |> Promise.then_(Fetch.Response.json)
20+
let fetchTodo = id =>
21+
j`https://jsonplaceholder.typicode.com/todos/$id`
22+
->Fetch.fetch
23+
->Promise.then_(Fetch.Response.json, _)
24+
->Promise.then_(value => Promise.resolve(Decode.todo(value)), _)
1625

1726
@react.component
1827
let make = () => {
19-
let (result, _) = TodoQuery.useQuery(~queryKey="/todos/1", ~queryFn=fetchTodo, ())
28+
let result = ReactQuery.useQueries([
29+
ReactQuery.queryOptions(~queryKey="/todo-1", ~queryFn=_ => fetchTodo(1), ()),
30+
ReactQuery.queryOptions(~queryKey="/todo-2", ~queryFn=_ => fetchTodo(2), ()),
31+
])
32+
33+
switch result {
34+
| [{data: Some(value)}, {data: Some(value2)}] => Js.log2(value, value2)
35+
| _ => Js.log("caboom!")
36+
}
2037

21-
<div>
22-
{switch result {
23-
| Error(_) => <div> {React.string("Loading...")} </div>
24-
| _ => <div> {React.string("Whatever....")} </div>
25-
}}
26-
</div>
38+
<div />
2739
}

examples/src/bindings/ReactQuery.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type queryClient
22

3-
module Query = ReactQuery_Query
3+
include ReactQuery_Query
4+
include ReactQuery_Utils
45

56
module Provider = {
67
@new @module("react-query")

0 commit comments

Comments
 (0)