Skip to content

Commit da479ab

Browse files
committed
Add solidjs docs
1 parent f53e819 commit da479ab

File tree

1 file changed

+102
-5
lines changed

1 file changed

+102
-5
lines changed

docs/installation/client.md

+102-5
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,47 @@ Next, initialize Vortex client and create your application root:
3232

3333
::: tabs
3434
== Svelte
35+
For Svelte 5, your entry file should have `svelte.js` extension and you will update your root props using `$state` rune:
36+
37+
**_app.svelte.js_**
38+
```js
39+
import { createVortex, subscribe, install } from '@westacks/vortex';
40+
import { core } from '@westacks/vortex/extensions'
41+
import { props as getProps } from './setup';
42+
import { mount, hydrate } from 'svelte'
43+
import App from './App.svelte';
44+
45+
createVortex(async (target, page, ssr) => {
46+
const props = $state(await getProps(page))
47+
const h = ssr ? hydrate : mount
48+
49+
h(App, {target, props})
50+
51+
install(core())
52+
subscribe(async (page) => Object.assign(props, await getProps(page)))
53+
})
54+
```
55+
Or in case you use older version of Svelte, you can use legacy class component syntax:
56+
3557
**_app.js_**
3658

37-
Create application root and subscribe to page changes.
3859
```js
39-
import { createVortex, subscribe } from '@westacks/vortex'
60+
import { createVortex, subscribe, install } from '@westacks/vortex'
61+
import { core } from '@westacks/vortex/extensions'
4062
import { props } from './setup'
4163
import App from './App.svelte'
4264

4365
createVortex(async (target, page, hydrate) => {
4466
const app = new App({ target, props: await props(page), hydrate })
4567

68+
install(core())
4669
subscribe(async (page) => app.$set(await props(page)))
4770
})
4871
```
72+
You will need to resolve page component, using your bundler's API. We will provide example for Vite as most popular, but code below may differ depending on bundler you are using.
73+
4974
**_setup.js_**
5075

51-
You will need to resolve page component, using your bundler's API. We will provide example for Vite as most popular, but code below may differ depending on bundler you are using.
5276
```js
5377
export const props = async (page) => {
5478
const pages = import.meta.glob('./pages/**/*.svelte')
@@ -68,7 +92,47 @@ export const props = async (page) => {
6892
{/if}
6993
```
7094
== Solid
71-
TODO
95+
**_app.jsx_**
96+
97+
Create application root and subscribe to page changes.
98+
```jsx
99+
import { createVortex, subscribe, install } from '@westacks/vortex';
100+
import { core } from '@westacks/vortex/extensions';
101+
import { createSignal } from 'solid-js';
102+
import { render, hydrate } from 'solid-js/web'
103+
import { App, props } from './setup';
104+
105+
createVortex(async (target, page, ssr) => {
106+
const [getProps, setProps] = createSignal(await props(page))
107+
const h = ssr ? hydrate : render
108+
109+
h(() => <App getProps={getProps}/>, target)
110+
111+
install(core())
112+
subscribe(async (page) => setProps(await props(page)))
113+
})
114+
115+
```
116+
**_setup.jsx_**
117+
118+
Here we will define application root and page component resolver. You will need to resolve page component, using your bundler's API. We will provide example for Vite as most popular, but code below may differ depending on bundler you are using.
119+
```jsx
120+
import { Dynamic } from "solid-js/web"
121+
122+
export const App = function ({ getProps }) {
123+
const component = () => getProps().component
124+
const props = () => getProps().props
125+
126+
return <Dynamic component={component()} {...props()} />
127+
}
128+
129+
export const props = async (page) => {
130+
const pages = import.meta.glob('./pages/**/*.jsx')
131+
const component = (await pages[`./pages/${page.component}.jsx`])?.default
132+
133+
return { component, props: page.props ?? {} }
134+
}
135+
```
72136
== Vue
73137
TODO
74138
== React
@@ -87,6 +151,25 @@ Optionally, you can setup bundle for server-side rendering (SSR), which can be u
87151
88152
::: tabs
89153
== Svelte
154+
Svelte 5
155+
156+
**_ssr.js_**
157+
```js
158+
import { createVortexServer } from '@westacks/vortex/server'
159+
import { render } from 'svelte/server'
160+
import { props } from './setup'
161+
import App from './App.svelte'
162+
163+
createVortexServer(async (page) => {
164+
const {html, head} = render(App, {props: await props(page)})
165+
166+
// You should return data type, that compatible with your server API
167+
return {body: html, head}
168+
})
169+
170+
```
171+
Svelte (legacy)
172+
90173
**_ssr.js_**
91174
```js
92175
import { createVortexServer } from '@westacks/vortex/server'
@@ -102,7 +185,21 @@ createVortexServer(async (page) => {
102185

103186
```
104187
== Solid
105-
TODO
188+
**_ssr.jsx_**
189+
```jsx
190+
import { createVortexServer } from '@westacks/vortex/server'
191+
import { renderToString, generateHydrationScript, getAssets } from 'solid-js/web'
192+
import { App, props } from './setup'
193+
194+
createVortexServer(async (page) => {
195+
const props = await props(page)
196+
const body = renderToString(() => <App getProps={() => props} />)
197+
198+
// You should return data type, that compatible with your server API
199+
return {body, head: [getAssets(), generateHydrationScript()]}
200+
})
201+
202+
```
106203
== Vue
107204
TODO
108205
== React

0 commit comments

Comments
 (0)