@colisweb/rescript-toolkit 2.60.0 → 2.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/fetcher/Toolkit__Fetcher.res +30 -8
- package/src/vendors/Swr.res +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.61.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rescript clean",
|
|
6
6
|
"build": "rescript build -with-deps",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"rescript-classnames": "6.0.0",
|
|
79
79
|
"rescript-react-update": "5.0.0",
|
|
80
80
|
"sanitize-html": "1.27.4",
|
|
81
|
-
"swr": "
|
|
81
|
+
"swr": "2.0.0",
|
|
82
82
|
"tailwindcss": "3.2.4"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
@@ -4,19 +4,16 @@ module type Config = {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
module Make = (Config: Config) => {
|
|
7
|
-
let key: Config.Request.argument => Swr.SwrKey.t =
|
|
7
|
+
let key: Config.Request.argument => Swr.SwrKey.t = arr =>
|
|
8
|
+
Config.key(arr)->Js.Array2.joinWith("--")->Swr.SwrKey.make
|
|
8
9
|
|
|
9
10
|
let use = (
|
|
10
11
|
~options: option<Swr.fetcherOptions>=?,
|
|
11
12
|
argument: option<Config.Request.argument>,
|
|
12
13
|
): Toolkit__Hooks.fetcher<Config.Request.response> =>
|
|
13
|
-
Toolkit__Hooks.useFetcher(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
() => {
|
|
17
|
-
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
18
|
-
},
|
|
19
|
-
)
|
|
14
|
+
Toolkit__Hooks.useFetcher(~options?, argument->Option.map(key), () => {
|
|
15
|
+
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
16
|
+
})
|
|
20
17
|
|
|
21
18
|
let useOptional = (
|
|
22
19
|
~options: option<Swr.fetcherOptions>=?,
|
|
@@ -26,3 +23,28 @@ module Make = (Config: Config) => {
|
|
|
26
23
|
Config.Request.exec(argument->Option.getExn)->Promise.Js.fromResult
|
|
27
24
|
})
|
|
28
25
|
}
|
|
26
|
+
|
|
27
|
+
module type MutationConfig = {
|
|
28
|
+
module Request: Toolkit__Request.Config
|
|
29
|
+
let key: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module MakeMutation = (Config: MutationConfig) => {
|
|
33
|
+
let key = Config.key->Swr.SwrKey.make
|
|
34
|
+
|
|
35
|
+
let useMutation = (
|
|
36
|
+
~options: option<Swr.mutationFetcherOptions<Config.Request.response>>=?,
|
|
37
|
+
key: string,
|
|
38
|
+
) => {
|
|
39
|
+
Swr.useSwrMutation(
|
|
40
|
+
Swr.SwrKey.make(key),
|
|
41
|
+
(_url, {arg}) => {
|
|
42
|
+
Config.Request.exec(arg)->Promise.Js.fromResult
|
|
43
|
+
},
|
|
44
|
+
switch options {
|
|
45
|
+
| Some(options) => options->Obj.magic
|
|
46
|
+
| None => {revalidate: true}
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/vendors/Swr.res
CHANGED
|
@@ -12,6 +12,7 @@ type fetcherOptions
|
|
|
12
12
|
@obj
|
|
13
13
|
external makeFetcherOptions: (
|
|
14
14
|
~suspense: bool=?,
|
|
15
|
+
~keepPreviousData: bool=?,
|
|
15
16
|
~fetcher: 'fetcher=?,
|
|
16
17
|
~fallbackData: 'data=?,
|
|
17
18
|
~revalidateOnFocus: bool=?,
|
|
@@ -43,16 +44,39 @@ type fetcher<'data> = {
|
|
|
43
44
|
data: option<'data>,
|
|
44
45
|
error: option<Js.Exn.t>,
|
|
45
46
|
isValidating: bool,
|
|
47
|
+
isLoading: bool,
|
|
46
48
|
mutate: (. unit) => Js.Promise.t<bool>,
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
type mutationFetcherOptions<'optimisticData> = {
|
|
52
|
+
optimisticData?: 'optimisticData => 'optimisticData,
|
|
53
|
+
revalidate?: bool,
|
|
54
|
+
populateCache?: bool,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type mutationFetcher<'params, 'data, 'error> = {
|
|
58
|
+
data: option<'data>,
|
|
59
|
+
error: option<Js.Exn.t>,
|
|
60
|
+
isMutating: bool,
|
|
61
|
+
trigger: 'params => Promise.Js.t<'data, 'error>,
|
|
62
|
+
}
|
|
63
|
+
|
|
49
64
|
module SwrKey = Toolkit__Identifier.MakeString()
|
|
50
65
|
|
|
51
66
|
@module("swr")
|
|
52
67
|
external useSwr: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<'data> = "default"
|
|
53
68
|
|
|
69
|
+
type mutationParams<'params> = {arg: 'params}
|
|
70
|
+
@module("swr/mutation")
|
|
71
|
+
external useSwrMutation: (
|
|
72
|
+
SwrKey.t,
|
|
73
|
+
(string, mutationParams<'params>) => 'response,
|
|
74
|
+
mutationFetcherOptions<'optimisticData>,
|
|
75
|
+
) => mutationFetcher<'params, 'data, 'error> = "default"
|
|
76
|
+
|
|
54
77
|
@module("swr")
|
|
55
|
-
external useSwrOptional: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<option<'data>> =
|
|
78
|
+
external useSwrOptional: (option<SwrKey.t>, 'fn, 'fetcherOptions) => fetcher<option<'data>> =
|
|
79
|
+
"default"
|
|
56
80
|
|
|
57
81
|
type cache
|
|
58
82
|
@module("swr") external cache: cache = "cache"
|