@@ -32,23 +32,47 @@ Next, initialize Vortex client and create your application root:
32
32
33
33
::: tabs
34
34
== 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
+
35
57
** _ app.js_ **
36
58
37
- Create application root and subscribe to page changes.
38
59
``` js
39
- import { createVortex , subscribe } from ' @westacks/vortex'
60
+ import { createVortex , subscribe , install } from ' @westacks/vortex'
61
+ import { core } from ' @westacks/vortex/extensions'
40
62
import { props } from ' ./setup'
41
63
import App from ' ./App.svelte'
42
64
43
65
createVortex (async (target , page , hydrate ) => {
44
66
const app = new App ({ target, props: await props (page), hydrate })
45
67
68
+ install (core ())
46
69
subscribe (async (page ) => app .$set (await props (page)))
47
70
})
48
71
```
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
+
49
74
** _ setup.js_ **
50
75
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.
52
76
``` js
53
77
export const props = async (page ) => {
54
78
const pages = import .meta.glob(' ./pages/**/*.svelte' )
@@ -68,7 +92,47 @@ export const props = async (page) => {
68
92
{/ if }
69
93
` ` `
70
94
== 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
+ ` ` `
72
136
== Vue
73
137
TODO
74
138
== React
@@ -87,6 +151,25 @@ Optionally, you can setup bundle for server-side rendering (SSR), which can be u
87
151
88
152
::: tabs
89
153
== 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
+
90
173
**_ssr.js_**
91
174
` ` ` js
92
175
import { createVortexServer } from ' @westacks/vortex/server'
@@ -102,7 +185,21 @@ createVortexServer(async (page) => {
102
185
103
186
` ` `
104
187
== 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
+ ` ` `
106
203
== Vue
107
204
TODO
108
205
== React
0 commit comments