Skip to content

Commit 627cbb4

Browse files
committed
Add installation guide for all frameworks
1 parent 2839fe6 commit 627cbb4

11 files changed

Lines changed: 604 additions & 395 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ export default defineConfig({
1717
{ text: 'Introduction', link: '/introduction', },
1818
{
1919
text: 'Installation',
20+
link: '/installation',
2021
items: [
21-
{ text: 'Server', link: '/installation/server' },
22-
{ text: 'Client', link: '/installation/client' },
22+
{ text: 'React', link: '/installation/react' },
23+
{ text: 'Vue', link: '/installation/vue' },
24+
{ text: 'Svelte', link: '/installation/svelte' },
25+
{ text: 'SolidJS', link: '/installation/solid-js' },
2326
]
2427
},
2528
{
2629
text: 'Usage',
2730
items: [
2831
{ text: 'Navigation', link: '/usage/navigation' },
29-
{ text: 'Extensions API', link: '/usage/extensions' },
3032
]
3133
}
3234
],

docs/installation.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Installation
2+
3+
Vortex is designed to be modular and framework-agnostic. Out of the box, it comes with official adapters for four popular frontend frameworks:
4+
5+
- **React** (`@westacks/vortex/react`)
6+
- **Vue** (`@westacks/vortex/vue`)
7+
- **Svelte** (`@westacks/vortex/svelte`)
8+
- **SolidJS** (`@westacks/vortex/solid-js`)
9+
10+
## Resolving and rendering page components
11+
12+
Depending on your app structure, you will need to create a logic to resolve and render your page components. The simplest setup - just a root component that will receive page component and its props, however you can customize it to your needs:
13+
14+
```tsx
15+
import type { Page } from '@westacks/vortex'
16+
17+
// Vite
18+
async function resolve(page: Page) {
19+
const pages = import.meta.glob('./pages/**/*.tsx')
20+
const component = await pages[`./pages/${page.component}.tsx`]
21+
return { component, props: page.props ?? {} }
22+
}
23+
24+
// Webpack
25+
async function resolve(page: Page) {
26+
const component = require(`./pages/${page.component}.tsx`),
27+
return { component, props: page.props ?? {} }
28+
}
29+
30+
export default function Root({ component, props }) {
31+
return <component.default {...props} />
32+
}
33+
```
34+
35+
## Extensions and Plugins
36+
37+
Vortex also have an extension API to enhance your application routing with different features. Out of the box, Vortex comes with pluging for [Inertia.js](https://inertiajs.com/) and [BProgress](https://bprogress.vercel.app/). You can install them when creating your app:
38+
39+
```ts
40+
import { createVortex } from '@westacks/vortex';
41+
import inertia from '@westacks/vortex/inertia';
42+
import bprogress from '@westacks/vortex/bprogress';
43+
44+
createVortex((target, page, install, ssr) => {
45+
install(inertia(page.get()), bprogress());
46+
// ...your app setup
47+
});
48+
```
49+
50+
## Creating Your Own Extension
51+
52+
You can easily plug your own extension into Vortex with followind template:
53+
54+
```ts
55+
import type { VortexExtension } from '@westacks/vortex';
56+
57+
export default const extension: VortexExtension = ({ request, response }) => {
58+
// initial configuration
59+
60+
// @see https://axios-http.com/docs/interceptors
61+
const req = request.use(
62+
(config) => config, // Modify request config, e.g. add headers etc
63+
(error) => Promise.reject(error), // Handle error
64+
);
65+
66+
const res = response.use(
67+
(response) => response, // Handle response data (after receiving response)
68+
(error) => Promise.reject(error), // Handle error
69+
);
70+
71+
return () => {
72+
// Cleanup
73+
request.eject(req)
74+
response.eject(res)
75+
}
76+
}
77+
```
78+
79+
```ts
80+
import { createVortex } from '@westacks/vortex';
81+
import extension from './extension';
82+
83+
createVortex((target, page, install, ssr) => {
84+
install(extension);
85+
// ...your app setup
86+
});
87+
```

docs/installation/client.md

Lines changed: 0 additions & 253 deletions
This file was deleted.

0 commit comments

Comments
 (0)