Skip to content

Commit c025b3e

Browse files
authored
Update arizona.svelte template to use arizona_svelte library (#22)
- Template now leverages @arizona-framework/svelte npm package and arizona_svelte Erlang lib - Simplified template structure by removing redundant local modules - Users get automatic component lifecycle monitoring out of the box - Enhanced developer experience with LifecycleDemo component - Templates are now lighter and leverage the robust arizona_svelte library - Perfect synergy: template generates projects that use the library based on this template Key architectural improvements: - External arizona_svelte library handles component management - Template focuses on project structure and configuration - Users benefit from maintained, tested library code - Cleaner separation between template and runtime functionality
1 parent 11d682b commit c025b3e

File tree

11 files changed

+40
-47
lines changed

11 files changed

+40
-47
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,15 @@ $ rebar3 new arizona.presence my_chat_app
9494
# Create a modern frontend application
9595
$ rebar3 new arizona.frontend my_web_app
9696
97-
# Create a full-stack Svelte application
97+
# Create a full-stack Svelte application (uses arizona_svelte library)
9898
$ rebar3 new arizona.svelte my_svelte_app
9999
```
100100
101+
> **Note**: The arizona.svelte template leverages the **arizona_svelte library**
102+
> for robust Svelte integration. This provides production-ready component management,
103+
> automatic lifecycle monitoring, and seamless Arizona-Svelte interoperability out
104+
> of the box.
105+
101106
## Templates
102107
103108
### Frontend Template
@@ -124,26 +129,36 @@ The app will be available at http://localhost:1912 with hot-reloading enabled.
124129
125130
### Svelte Template
126131
127-
The Svelte template creates a full-stack Arizona application with Svelte integration:
132+
The Svelte template creates a full-stack Arizona application powered by the
133+
**arizona_svelte library**:
128134
135+
- **Arizona Svelte Library** - Production-ready Erlang/OTP and npm packages for
136+
Svelte integration
137+
- **Automatic Component Lifecycle** - Components mount/unmount automatically
138+
with DOM changes
129139
- **Svelte 5** - Modern reactive frontend framework with runes
130140
- **Vite** - Fast build tool with hot module replacement
131141
- **Tailwind CSS v4** - Modern utility-first CSS framework
132-
- **Component architecture** - HelloWorld and Counter Svelte components
133-
- **Hot-reloading** - Both CSS and JS changes reload automatically
134-
- **Arizona-Svelte bridge** - Seamless integration between server and client
135-
- **Hybrid rendering** - Server-side Arizona components with embedded Svelte components
142+
- **Interactive Demo Components** - HelloWorld, Counter, and LifecycleDemo components
143+
- **Real-time Monitoring** - Built-in component lifecycle monitoring and logging
144+
- **WebSocket Integration** - Automatic re-mounting after Arizona HTML patches
145+
- **Developer Tools** - Global `arizonaSvelte` debugging interface
136146
137147
After creating a Svelte template project:
138148
139149
```bash
140150
cd myapp
141-
npm install # Install dependencies
151+
npm install # Install dependencies (includes @arizona-framework/svelte)
142152
npm run build # Build CSS and JS
143153
rebar3 shell # Start the Arizona server
144154
```
145155
146-
The app will be available at http://localhost:1912 with full hot-reloading for both CSS and Svelte components.
156+
The app will be available at http://localhost:1912 with:
157+
158+
- **Automatic component management** - No manual mounting/unmounting needed
159+
- **Full hot-reloading** for both CSS and Svelte components
160+
- **Interactive lifecycle demo** for testing and learning
161+
- **Production-ready architecture** leveraging the arizona_svelte library
147162
148163
### Controls
149164

priv/templates/arizona.svelte.template

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{template, "arizona.svelte/assets/svelte/components/Counter.svelte", "{{name}}/assets/svelte/components/Counter.svelte"}.
1616
{template, "arizona.svelte/assets/svelte/components/HelloWorld.svelte", "{{name}}/assets/svelte/components/HelloWorld.svelte"}.
1717
{template, "arizona.svelte/assets/svelte/components/LifecycleDemo.svelte", "{{name}}/assets/svelte/components/LifecycleDemo.svelte"}.
18+
{template, "arizona.svelte/assets/svelte/components/index.js", "{{name}}/assets/svelte/components/index.js"}.
1819
{template, "arizona.svelte/assets/tailwind.config.js", "{{name}}/assets/tailwind.config.js"}.
1920
{template, "arizona.svelte/assets/vite.config.js", "{{name}}/assets/vite.config.js"}.
2021

@@ -35,14 +36,11 @@
3536

3637
{template, "arizona.svelte/src/app.src", "{{name}}/src/{{name}}.app.src"}.
3738
{template, "arizona.svelte/src/app.erl", "{{name}}/src/{{name}}_app.erl"}.
38-
{template, "arizona.svelte/src/components.erl", "{{name}}/src/{{name}}_components.erl"}.
3939
{template, "arizona.svelte/src/counter.erl", "{{name}}/src/{{name}}_counter.erl"}.
4040
{template, "arizona.svelte/src/css_reloader.erl", "{{name}}/src/{{name}}_css_reloader.erl"}.
4141
{template, "arizona.svelte/src/js_reloader.erl", "{{name}}/src/{{name}}_js_reloader.erl"}.
4242
{template, "arizona.svelte/src/layout.erl", "{{name}}/src/{{name}}_layout.erl"}.
43-
{template, "arizona.svelte/src/main.erl", "{{name}}/src/{{name}}.erl"}.
4443
{template, "arizona.svelte/src/sup.erl", "{{name}}/src/{{name}}_sup.erl"}.
45-
{template, "arizona.svelte/src/template.erl", "{{name}}/src/{{name}}_template.erl"}.
4644
{template, "arizona.svelte/src/view.erl", "{{name}}/src/{{name}}_view.erl"}.
4745

4846
%% /
@@ -51,4 +49,4 @@
5149
{template, "arizona.svelte/LICENSE.md", "{{name}}/LICENSE.md"}.
5250
{template, "arizona.svelte/package.json", "{{name}}/package.json"}.
5351
{template, "arizona.svelte/README.md", "{{name}}/README.md"}.
54-
{template, "arizona.svelte/rebar.config", "{{name}}/rebar.config"}.
52+
{template, "arizona.svelte/rebar.config", "{{name}}/rebar.config"}.

priv/templates/arizona.svelte/assets/js/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Arizona from '@arizona-framework/client';
2-
import ArizonaSvelte from './arizona-svelte.js';
2+
import ArizonaSvelte from '@arizona-framework/svelte';
3+
import * as components from '../svelte/components';
34

45
// Initialize Arizona framework
56
globalThis.arizona = new Arizona({ logLevel: 'debug' });
6-
arizona.connect({ wsPath: '/live' });
7+
arizona.connect('/live');
78

89
// Initialize ArizonaSvelte with automatic monitoring
9-
const arizonaSvelte = new ArizonaSvelte();
10+
const arizonaSvelte = new ArizonaSvelte({ components });
1011

1112
// Start automatic monitoring - components will mount/unmount automatically
1213
arizonaSvelte.startMonitoring({
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Counter } from './Counter.svelte';
2+
export { default as HelloWorld } from './HelloWorld.svelte';
3+
export { default as LifecycleDemo } from './LifecycleDemo.svelte';

priv/templates/arizona.svelte/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"vite": "^7.1.7"
2424
},
2525
"dependencies": {
26-
"@arizona-framework/client": "^0.2.0"
26+
"@arizona-framework/client": "^0.2.0",
27+
"@arizona-framework/svelte": "^0.2.0"
2728
}
2829
}

priv/templates/arizona.svelte/rebar.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
{arizona, {git, "https://github.com/arizona-framework/arizona.git",
77
{branch, "main"}}},
88
{arizona_rebar3_plugin, {git, "https://github.com/arizona-framework/arizona_rebar3_plugin",
9-
{branch, "main"}}}
9+
{branch, "main"}}},
10+
{arizona_svelte, {git, "https://github.com/arizona-framework/arizona_svelte.git",
11+
{branch, "main"}}}
1012
]}.
1113

1214
{plugins, [

priv/templates/arizona.svelte/src/components.erl

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

priv/templates/arizona.svelte/src/counter.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ render(Bindings) ->
6969
<div class="text-xs text-arizona-teal/70 mb-2 text-center font-mono">
7070
↳ Svelte Component embedded inside Arizona Stateful Component
7171
</div>
72-
{{{name}}:render_component(~"Counter", #{
72+
{arizona_svelte:render_component(~"Counter", #{
7373
title => ~"Svelte Counter (Client-side)",
7474
initialCount => arizona_template:get_binding(count, Bindings)
7575
})}

priv/templates/arizona.svelte/src/main.erl

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

priv/templates/arizona.svelte/src/template.erl

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

0 commit comments

Comments
 (0)