Skip to content

Commit 386dac6

Browse files
committed
docs: add solidjs examples, optimize docs
1 parent aef44b5 commit 386dac6

File tree

29 files changed

+1171
-368
lines changed

29 files changed

+1171
-368
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
title: Question and Answer
2+
title: FAQs
33
---
44

5-
import Tabs from '@theme/Tabs';
6-
import TabItem from '@theme/TabItem';
7-
85
## Why to create alova?
96

107
Data requests have always been an indispensable and important part of applications. Since the birth of XMLHttpRequest, request schemes have emerged in endlessly. Client-side data interaction exploration has always focused on the simplicity of requests, such as `$.ajax`, `axios`, `fetch api` and Request tools such as `react-query`, the coding form continues to evolve from callback functions, Promise, to usehook. These js libraries have done a good job in making requests simple, but they only provide common functions, which means For different request scenarios such as sharing requests, paging requests, form submissions, uploading and downloading files, etc., developers still need to write complex codes themselves, which reduces development efficiency and performance cannot be guaranteed. As user experience becomes more and more important, In this era, application fluency has become more and more important.
@@ -28,3 +25,7 @@ Decoupling a js library means using it in more scenarios. For example, axios can
2825
## Why does the request function use PascalCase specification?
2926

3027
Different from the axios, taking the GET method as an example, `axios.get` is a request action, while `alova.Get` creates a method instance but actually does not send request.
28+
29+
## Troubleshooting
30+
31+
Refer to [Troubleshooting](/tutorial/project/troubleshooting)

docs/resource/01-request-adapter/05-uniapp.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ yarn add @alova/adapter-uniapp
3030
</TabItem>
3131
</Tabs>
3232

33+
:::warning
34+
35+
In uniapp+vite, `@rollup/plugin-node-resolve` needs to be configured, otherwise it may cause an error that the dependency cannot be found.
36+
37+
[#535 discussion](https://github.com/orgs/alovajs/discussions/535)
38+
39+
```js
40+
import { defineConfig } from 'vite';
41+
import uni from '@dcloudio/vite-plugin-uni';
42+
import { nodeResolve } from '@rollup/plugin-node-resolve';
43+
44+
export default defineConfig({
45+
plugins: [uni(), nodeResolve()]
46+
});
47+
```
48+
49+
:::
50+
3351
## Usage
3452

3553
### create alova

docs/tutorial/02-getting-started/01-introduce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Alova (pronounced as `/əˈləʊva/` <AudioPlayer src={tts} />) is a workflow-st
2020

2121
Different from `@tanstack/react-request`, `swrjs`, `ahooks's useRequest`, etc. library, `alova` is a comprehensive request tool, alova makes your request integration very simple and maintains more efficient Client-Server data interaction. In addition, you can use it in client and server environments (including SSR).
2222

23-
Here is a detailed comparison [with other request libraries](/about/comparison).
23+
You can read the backstory on [why create alova](/about/faqs), and we've also provided a detailed [comparison to other request libraries](/about/comparison) to see how alova differs.
2424

2525
In addition, alova also has the following features:
2626

docs/tutorial/02-getting-started/03-basic/07-combine-framework.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import useRequestSolid from '!!raw-loader!@site/codesandbox@3/01-getting-started
1414

1515
Next, we will learn how to use it in conjunction with the client UI framework, which can allow alova to exert its true power. When used in the UI framework, not only can alova automatically manage the responsive request status, but also automatically control when the request should be sent through certain rules.
1616

17-
`alova` provides 10+ client request strategies, which help you implement complex requests in a simple and elegant way. Let's continue to look down!
17+
`alova` provides 15+ client request strategies, which help you implement complex requests in a simple and elegant way. Let's continue to look down!
1818

1919
## Set statesHook
2020

21-
Before using the request strategy, we need to set the corresponding statesHook on the alova instance. It must correspond to the UI framework used by the project. This is very important. It will tell alova that it should create responsive states for the corresponding UI framework. Currently, the following frameworks are supported:
21+
Alova's useHook request strategy can run in all UI frameworks supported by Alova. You only need to set the statesHook of the corresponding UI framework on the Alova instance, which will tell Alova which UI framework should be used to create states.
2222

2323
<Tabs groupId="framework">
2424

@@ -82,9 +82,29 @@ export const alovaInstance = createAlova({
8282
});
8383
```
8484

85+
</TabItem>
86+
<TabItem value="5" label="vue-demi">
87+
88+
```js
89+
import { createAlova } from 'alova';
90+
import VueDemiHook from 'alova/vue-demi';
91+
92+
// support [email protected]+ composition api
93+
export const alovaInstance = createAlova({
94+
// ...
95+
// highlight-start
96+
statesHook: VueDemiHook
97+
// highlight-end
98+
});
99+
```
100+
85101
</TabItem>
86102
</Tabs>
87103

104+
In addition, alova also provides the following statesHooks:
105+
106+
- [statesHook for vue options style](/resource/framework/vue-options), which means you can use alova's usehooks in vue2's options style components.
107+
88108
## Automatically manage request status
89109

90110
`useRequest` is our most commonly used request strategy. It can help us create and maintain responsive states of requests, such as `loading/data/error`, etc. You can use these responsive states directly in the view. When they change, the view will also change accordingly.

docs/tutorial/03-client/01-strategy/04-use-pagination.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,91 @@ const App = () => {
268268
<span>A total of {total} pieces of data</span>
269269
```
270270

271+
</TabItem>
272+
<TabItem value="4" label="solid">
273+
274+
```jsx
275+
import { queryStudents } from './api.js';
276+
import { usePagination } from 'alova/client';
277+
278+
const App = () => {
279+
const {
280+
// loading state
281+
loading,
282+
283+
// list data
284+
data,
285+
286+
// is it the last page
287+
// This parameter can be used to determine whether it needs to be loaded during pull-down loading
288+
isLastPage,
289+
290+
// The current page number, changing this page number will automatically trigger the request
291+
page,
292+
293+
// Number of data items per page
294+
pageSize,
295+
296+
// number of paging pages
297+
pageCount,
298+
299+
// total amount of data
300+
total,
301+
302+
// update states
303+
update
304+
} = usePagination(
305+
// Method instance acquisition function, it will receive page and pageSize, and return a Method instance
306+
(page, pageSize) => queryStudents(page, pageSize),
307+
{
308+
// Initial data before the request (data format returned by the interface)
309+
initialData: {
310+
total: 0,
311+
data: []
312+
},
313+
initialPage: 1, // initial page number, default is 1
314+
initialPageSize: 10 // The initial number of data items per page, the default is 10
315+
}
316+
);
317+
318+
// Turn to the previous page, the request will be sent automatically after the page value changes
319+
const handlePrevPage = () => {
320+
update({
321+
page: page() - 1
322+
});
323+
};
324+
325+
// Turn to the next page, the request will be sent automatically after the page value changes
326+
const handleNextPage = () => {
327+
update({
328+
page: page() + 1
329+
});
330+
};
331+
332+
// Change the number of pages, the request will be sent automatically after the pageSize value is changed
333+
const handleSetPageSize = () => {
334+
update({
335+
pageSize: 20
336+
});
337+
};
338+
339+
return (
340+
<div>
341+
{data().map(item => (
342+
<div key={item.id}>
343+
<span>{item.name}</span>
344+
</div>
345+
))}
346+
<button onClick={handlePrevPage}>Previous page</button>
347+
<button onClick={handleNextPage}>Next Page</button>
348+
<button onClick={handleSetPageSize}>Set the number per page</button>
349+
<span>There are {pageCount()} pages</span>
350+
<span>A total of {total()} pieces of data</span>
351+
</div>
352+
);
353+
};
354+
```
355+
271356
</TabItem>
272357
</Tabs>
273358

@@ -415,6 +500,7 @@ For example, filter by student name, student grade.
415500
```jsx
416501
import { queryStudents } from './api.js';
417502
import { usePagination } from 'alova/client';
503+
import { useState } from 'react';
418504

419505
const App = () => {
420506
// search condition status
@@ -480,6 +566,45 @@ const App = () => {
480566
```
481567

482568
</TabItem>
569+
<TabItem value="4" label="solid">
570+
571+
```jsx
572+
import { queryStudents } from './api.js';
573+
import { usePagination } from 'alova/client';
574+
import { createSignal } from 'solid-js';
575+
576+
const App = () => {
577+
// search condition status
578+
const [studentName, setStudentName] = createSignal('');
579+
const [clsName, setClsName] = createSignal('');
580+
const {
581+
//...
582+
} = usePagination(
583+
(page, pageSize) => queryStudents(page, pageSize, studentName(), clsName()),
584+
{
585+
//...
586+
// highlight-start
587+
watchingStates: [studentName, clsName]
588+
// highlight-end
589+
}
590+
);
591+
592+
return (
593+
// highlight-start
594+
<input value={studentName()} onChange={({ target }) => setStudentName(target.value)} />
595+
<select value={clsName()} onChange={({ target }) => setClsName(target.value)}>
596+
<option value="1">Class 1</option>
597+
<option value="2">Class 2</option>
598+
<option value="3">Class 3</option>
599+
</select>
600+
// highlight-end
601+
//...
602+
);
603+
};
604+
```
605+
606+
</TabItem>
607+
483608
</Tabs>
484609

485610
Same as `useWatcher`, you can also implement request debounce by specifying `debounce`, for details, please refer to [useWatcher's debounce parameter setting](/api/core-hooks#usewatcher).

docs/tutorial/03-client/01-strategy/05-use-form.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,78 @@ const App = () => {
226226
</button>
227227
```
228228

229+
</TabItem>
230+
<TabItem value="4" label="solid">
231+
232+
```jsx
233+
import { formSubmit } from './api.js';
234+
import { useForm } from 'alova/client';
235+
236+
const App = () => {
237+
const {
238+
// submit status
239+
loading: submitting,
240+
241+
// Responsive form data, the content is determined by initialForm
242+
form,
243+
244+
// submit data function
245+
send: submit,
246+
247+
// update form item
248+
updateForm,
249+
250+
// Submit successful callback binding
251+
onSuccess,
252+
253+
// Submit failure callback binding
254+
onError,
255+
256+
// Submit completed callback binding
257+
onComplete
258+
} = useForm(
259+
formData => {
260+
// Form data can be converted and submitted here
261+
return formSubmit(formData);
262+
},
263+
{
264+
// Initialize form data
265+
initialForm: {
266+
name: '',
267+
cls: '1'
268+
}
269+
}
270+
);
271+
272+
// submit form data
273+
const handleSubmit = () => {
274+
// Validate form data...
275+
submit();
276+
};
277+
278+
return (
279+
<div>
280+
<input
281+
value={form().name}
282+
onChange={({ target }) => updateForm({ name: target.value })}
283+
/>
284+
<select
285+
value={form().cls}
286+
onChange={({ target }) => updateForm({ cls: target.value })}>
287+
<option value="1">class 1</option>
288+
<option value="2">class 2</option>
289+
<option value="3">class 3</option>
290+
</select>
291+
<button
292+
onClick={handleSubmit}
293+
loading={submitting()}>
294+
submit
295+
</button>
296+
</div>
297+
);
298+
};
299+
```
300+
229301
</TabItem>
230302
</Tabs>
231303

@@ -293,8 +365,7 @@ const {
293365
});
294366

295367
// Request form data and update it to the form
296-
const { onSuccess } = useRequest(getData);
297-
onSuccess(({ data }) => {
368+
useRequest(getData).onSuccess(({ data }) => {
298369
updateForm({
299370
name: data.name,
300371
cls: data.cls

docs/tutorial/03-client/01-strategy/09-seamless-data-interaction/03-start-silent-factory.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@ import TabItem from '@theme/TabItem';
77

88
The silent queue is not started by default, and we need to specify the startup parameters for initialization. In general, call `bootSilentFactory` in the entry file to initialize the silent factory, which will read unexecuted requests to the corresponding silent through the specified configuration items queues and start those queues.
99

10-
<Tabs groupId="framework">
11-
<TabItem value="1" label="vue">
12-
13-
```javascript
14-
import { bootSilentFactory } from 'alova/client';
15-
import { alovaInst } from '@/api';
16-
17-
bootSilentFactory({
18-
// Specify the alova instance at startup to request information storage and request sending
19-
alova: alovaInst,
20-
21-
// Delay start time, in milliseconds, the default is 2000ms, see the follow-up instructions for details
22-
delay: 1000
23-
});
24-
```
25-
26-
</TabItem>
27-
28-
<TabItem value="2" label="react">
29-
30-
```javascript
10+
```javascript title="main.js"
3111
import { bootSilentFactory } from 'alova/client';
3212
import { alovaInst } from '@/api';
3313

@@ -40,26 +20,6 @@ bootSilentFactory({
4020
});
4121
```
4222

43-
</TabItem>
44-
45-
<TabItem value="3" label="svelte">
46-
47-
```javascript
48-
import { bootSilentFactory } from 'alova/client';
49-
import { alovaInst } from '@/api';
50-
51-
bootSilentFactory({
52-
// Specify the alova instance at startup to request information storage and request sending
53-
alova: alovaInst,
54-
55-
// Delay start time, in milliseconds, the default is 2000ms, see the follow-up instructions for details
56-
delay: 1000
57-
});
58-
```
59-
60-
</TabItem>
61-
</Tabs>
62-
6323
:::warning `delay` parameter description
6424

6525
In actual scenarios, when entering the current page, a request is also sent to load the page data. In order to ensure that the user can see the page data faster, the request to load the data needs to be forwarded to the beginning of the queue, otherwise it may cause the loading data to fail. The request is placed at the end of the queue. At this time, it is necessary to wait until all the previous requests are completed before loading the page data. This is obviously inappropriate. Therefore, by delaying initialization for a period of time, the request for loading data enters the queue first to achieve "queue jumping" effect, the specific delay time depends on the time required for page rendering.

0 commit comments

Comments
 (0)