Skip to content

Commit 8a59c62

Browse files
authored
feat: 🎸 简化注册 client 流程 (#57)
Co-authored-by: WhimsFate <[email protected]>
1 parent b7e378f commit 8a59c62

File tree

10 files changed

+15
-11
lines changed

10 files changed

+15
-11
lines changed

packages/mini-app-demo/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function createApp() {
8484
return data.data;
8585
});
8686

87-
store.registerClient('REST', restClient);
87+
store.registerClient(restClient);
8888

8989
app.use(store);
9090

packages/model/docs/guide/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ restClient.interceptors.response.use(({ data }) => {
3535
});
3636
```
3737

38-
详细`options`配置与`拦截器配置`,请参考[createClient](../api/client.md#createclient)
38+
详细`options`配置与`拦截器配置`,请参考[createClient](../api/client.md#createclient)

packages/model/docs/guide/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import CompositionAPI, { createApp, h } from '@vue/composition-api';
2020

2121
Vue.use(CompositionAPI);
2222

23-
const restClient = createClient('rest', {
23+
const restClient = createClient('REST', {
2424
method: 'post',
2525
timeout: 10 * 1000,
2626
});
@@ -46,7 +46,7 @@ restClient.interceptors.response.use(({ data }) => {
4646
const store = createStore();
4747

4848
// 注册对应的Client
49-
store.registerClient('REST', restClient);
49+
store.registerClient(restClient);
5050

5151
// 绑定Store与app实例的关系
5252
app.use(store);

packages/model/docs/guide/store.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ app.use(store);
1616
注册对应client,**注意** client为单例模式
1717
```typescript
1818
// 注册Rest Client
19-
store.registerClient('REST', restClient);
19+
const restClient = createClient('REST')
20+
store.registerClient(restClient);
2021
// 注册GQL Client,暂不可用
21-
store.registerClient('GQL', restClient);
22+
const gqlClient = createClient('GQL')
23+
store.registerClient(gqlClient);
2224
```

packages/model/examples/client/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function createApp(customFetch?: Fetch) {
2222
return res.data;
2323
});
2424

25-
store.registerClient('REST', restClient);
25+
store.registerClient(restClient);
2626
const app = createSSRApp({
2727
render: () => h(App),
2828
});

packages/model/src/__test__/api.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe(`model should has it's own effect scope`, () => {
1616
const store = createStore();
1717
const client = createClient('REST');
1818

19-
store.registerClient('REST', client);
19+
store.registerClient(client);
2020

2121
const app = createApp({
2222
render: () => h(App)

packages/model/src/__test__/server.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe(`model should has it's own effect scope`, () => {
2121
return JSON.parse(data.data);
2222
});
2323

24-
store.registerClient('REST', client);
24+
store.registerClient(client);
2525

2626
const app = createSSRApp(App);
2727
app.use(store, true);

packages/model/src/clients/client-factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,6 @@ export function clientFactory(
311311
interceptors,
312312
query: requestWithCache,
313313
mutate: request,
314+
type
314315
};
315316
}

packages/model/src/model/__test__/fn-type.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727

2828
import { MockModel, MockComposeModel } from './mock-models/fn-type';
2929
import 'unfetch/polyfill'
30+
import { isFetchMoreState } from '../../operations';
3031

3132
const restClient = createClient('REST', {
3233
method: 'post',

packages/model/src/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export function createStore() {
5757

5858
const rebornClient: RebornClient = {};
5959

60-
function registerClient(type: 'REST' | 'GQL', client: Client): void {
61-
if (type === 'REST') {
60+
function registerClient(client: Client): void {
61+
if (client.type === 'REST') {
6262
if (rebornClient.rest) {
6363
console.warn('You have already registered a restClient yet');
6464
return;

0 commit comments

Comments
 (0)