@@ -4,9 +4,54 @@ order: 2
44toc : menu
55---
66
7- ## @ querycap/bootstrap
7+ ## 配置
88
9- 创建一个 React 应用入口,内部会初始化 history、store、持久化数据、redux-logger,创建根组件,最终将
9+ @querycap/config 用于解析项目下 config.ts 文件,并将配置对象传入全局 ConfigProvider,
10+ 使用时可以通过 useConfig 获取。
11+
12+ 使用
13+
14+ ``` ts
15+ import { NotificationHub , Confirmations } from ' @querycap-canary/dashboard' ;
16+ import { ThemeProvider } from ' @querycap-ui/core/macro' ;
17+ import { patchBearerToken } from ' @querycap/access' ;
18+ import { createBootstrap } from ' @querycap/bootstrap' ;
19+ import { useConfig } from ' @querycap/config' ;
20+ import { AxiosProvider , baseURLsFromConfig } from ' @querycap/request' ;
21+ import { useStore } from ' @reactorx/core' ;
22+ import { ReactNode } from ' react' ;
23+ import { conf } from ' ./config' ;
24+ import { CSSPreset } from ' ./CSSPreset' ;
25+ import { rootRoutes } from ' ./routes' ;
26+
27+ const Setup = ({ children }: { children: ReactNode }) => {
28+ const store$ = useStore ();
29+ const c = useConfig ();
30+
31+ return (
32+ <ThemeProvider >
33+ <CSSPreset >
34+ < Confirmations / >
35+ < NotificationHub / >
36+ < AxiosProvider
37+ baseURLs = {baseURLsFromConfig(c )}
38+ interceptors = {[patchBearerToken (store$ )]}
39+ >
40+ {children}
41+ </AxiosProvider>
42+ </CSSPreset>
43+ </ThemeProvider>
44+ );
45+ };
46+
47+ export const bootstrap = createBootstrap(conf())(() => (
48+ <Setup>{rootRoutes}</Setup>
49+ ));
50+ ```
51+
52+ ## 启动
53+
54+ @querycap/bootstrap 创建一个 React 应用入口,内部会初始化 history、store、持久化数据、redux-logger,创建根组件,最终将
1055根组件以 ReactDOM.render 挂载到根节点。
1156
1257```ts
@@ -83,24 +128,58 @@ export const bootstrap = createBootstrap(conf())(() => (
83128### useTempDataOfRequest
84129
85130```ts
86- const [data , request , requesting$ ] = useTempDataOfRequest(apiFn, params, watchers, cacheKey);
131+ declare const useTempDataOfRequest: <TRequestActor extends RequestActor <
132+ any ,
133+ any
134+ >>(
135+ requestActor : TRequestActor ,
136+ arg : TRequestActor [' arg' ],
137+ deps ? : any [],
138+ cacheKey ? : string | undefined ,
139+ ) => readonly [
140+ TRequestActor [' done' ][' arg' ][' data' ] | undefined ,
141+ (
142+ req : TRequestActor [' arg' ] | undefined ,
143+ opt ? :
144+ | (axios .AxiosRequestConfig & {
145+ requestOptsFromReq? :
146+ | ((
147+ arg : TRequestActor [' arg' ],
148+ ) => _reactorx_request .IRequestOpts <any >)
149+ | undefined ;
150+ } & Pick <
151+ _reactorx_request .IUseRequestOpts <
152+ TRequestActor [' arg' ],
153+ TRequestActor [' opts' ],
154+ IStatusError
155+ >,
156+ ' onSuccess' | ' onFail'
157+ >)
158+ | undefined ,
159+ ) => void ,
160+ rxjs .BehaviorSubject <boolean >,
161+ ];
87162` ` `
88163
89164用于组件挂载完成时发起请求。
165+
90166请求发出的时机:
91167
92- - 组件实例第一次挂载后(componentDidMount);
93- - watchers 数组中任意值变化(浅比较);
168+ - 组件实例第一次挂载后;
169+ - deps 数组中任意值变化(浅比较);
170+
171+ 参数:
172+
173+ - requestActor:必传,src-clients/xxx 下对应自动生成的网关接口函数;
174+ - arg:必传,请求的参数(token 不用传,拦截器中默认写入 header 中了);
175+ - deps:可选,数组(同 useEffect),当改数组中任何一个值变化(浅比较),都会重新发起请求;
176+ - cacheKey:可选,字符串。标定当前请求通道的唯一性。主要用于多个请求(同一接口,不同请求参数)同时发起时, 用于区分。
94177
95178返回值:
96179
97180- data: 200 时的响应数据,默认:undefined;
98181- request:手动再次发起请求的方法,参数为请求参数 或 undefined(表示使用默认的请求参数);
99182- requesting\$ : 表示是否请求中的 observable,通常使用 useObservable 获取该布尔值;
100- - apiFn :必传,src - clients / xxx 下对应自动生成的网关接口函数;
101- - params :必传,请求的参数(token 不用传,拦截器中默认写入 header 中了);
102- - watchers :可选,数组(同 useEffect ),当改数组中任何一个值变化(浅比较),都会重新发起请求;
103- - cacheKey :可选,字符串。标定当前请求通道的唯一性。主要用于多个请求(同一接口,不同请求参数)同时发起时, 用于区分。
104183
105184` ` ` ts
106185import { useInstance } from ' @querycap-canary/oauth/Instance' ;
@@ -300,7 +379,7 @@ const IssueList = () => {
300379
301380## 权限
302381
303- @querycap/access 下包含用户信息 、权限认证相关的模块。
382+ @querycap/access 下包含 Token 信息 、权限认证相关的模块。
304383
305384### AccessControlProvider
306385
@@ -396,11 +475,11 @@ export const getRouterByStrategy = (strategy: string) => {
396475
397476### useAccess
398477
399- 获取用户信息
478+ 获取登陆 Token 信息
400479
401480### useAccessMgr
402481
403- 对用户信息进行获取 、修改、删除
482+ 对 Token 信息进行获取 、修改、删除
404483
405484` ` ` ts
406485const [access$ , set , del ] = useAccessMgr ();
@@ -1349,3 +1428,22 @@ declare function createUseState<T>(
13491428 },
13501429): () => readonly [any , (stateOrUpdater : T | TUpdater <T >) => void ];
13511430` ` `
1431+
1432+ ### useQueryState
1433+
1434+ ` ` ` ts
1435+ declare const useQueryState : <T extends string | string []>(
1436+ queryKey : string ,
1437+ defaultValue : T ,
1438+ ) => readonly [T , react .Dispatch <react .SetStateAction <T >>];
1439+ ` ` `
1440+
1441+ 用于将数据同步到 url 上的 query 参数上
1442+
1443+ 使用:
1444+
1445+ ` ` ` ts
1446+ const [search , setSearch ] = useQueryState (' key' , ' value' );
1447+ ` ` `
1448+
1449+ 当每次调用 setSearch 的时候,url 上的参数也会同步改变。
0 commit comments