Ember Octane vs Svelte 4 Comparison
Reactivity
Declare state
Ember Octane
name.hbs
<h1>Hello {{this.name}}</h1>
Svelte 4
Name.svelte
<script>
let name = "John";
</script>
<h1>Hello {name}</h1>
Update state
Ember Octane
name.hbs
<h1>Hello {{this.name}}</h1>
Svelte 4
Name.svelte
<script>
let name = "John";
name = "Jane";
</script>
<h1>Hello {name}</h1>
Computed state
Ember Octane
double-count.hbs
<div>{{this.doubleCount}}</div>
Svelte 4
DoubleCount.svelte
<script>
let count = 10;
$: doubleCount = count * 2;
</script>
<div>{doubleCount}</div>
Templating
Minimal template
Ember Octane
hello-world.hbs
<h1>Hello world</h1>
Svelte 4
HelloWorld.svelte
<h1>Hello world</h1>
Styling
Ember Octane
css-style.css
/* using: https://github.com/salsify/ember-css-modules */
.title {
color: red;
}
Svelte 4
CssStyle.svelte
<h1 class="title">I am red</h1>
<button style="font-size: 10rem;">I am a button</button>
<style>
.title {
color: red;
}
</style>
Loop
Ember Octane
colors.hbs
<ul>
{{#each (array "red" "green" "blue") as |color|}}
<li>{{color}}</li>
{{/each}}
</ul>
Svelte 4
Colors.svelte
<script>
const colors = ["red", "green", "blue"];
</script>
<ul>
{#each colors as color (color)}
<li>{color}</li>
{/each}
</ul>
Event click
Ember Octane
counter.hbs
<p>Counter: {{this.count}}</p>
<button {{on "click" this.incrementCount}}>+1</button>
Svelte 4
Counter.svelte
<script>
let count = 0;
function incrementCount() {
count++;
}
</script>
<p>Counter: {count}</p>
<button on:click={incrementCount}>+1</button>
Dom ref
Ember Octane
input-focused.hbs
<input {{this.autofocus}} />
Svelte 4
InputFocused.svelte
<script>
import { onMount } from "svelte";
let inputElement;
onMount(() => {
inputElement.focus();
});
</script>
<input bind:this={inputElement} />
Conditional
Ember Octane
traffic-light.hbs
<button {{on "click" this.nextLight}}>Next light</button>
<p>Light is: {{this.light}}</p>
<p>
You must
{{#if (eq this.light "red")}}
STOP
{{else if (eq this.light "orange")}}
SLOW DOWN
{{else if (eq this.light "green")}}
GO
{{/if}}
</p>
Svelte 4
TrafficLight.svelte
<script>
const TRAFFIC_LIGHTS = ["red", "orange", "green"];
let lightIndex = 0;
$: light = TRAFFIC_LIGHTS[lightIndex];
function nextLight() {
lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length;
}
</script>
<button on:click={nextLight}>Next light</button>
<p>Light is: {light}</p>
<p>
You must
{#if light === "red"}
<span>STOP</span>
{:else if light === "orange"}
<span>SLOW DOWN</span>
{:else if light === "green"}
<span>GO</span>
{/if}
</p>
Lifecycle
On mount
Ember Octane
page-title.hbs
<p>Page title is: {{(this.pageTitle)}}</p>
Svelte 4
PageTitle.svelte
<script>
import { onMount } from "svelte";
let pageTitle = "";
onMount(() => {
pageTitle = document.title;
});
</script>
<p>Page title: {pageTitle}</p>
On unmount
Ember Octane
time.hbs
<p>Current time: {{this.time}}</p>
Svelte 4
Time.svelte
<script>
import { onDestroy } from "svelte";
let time = new Date().toLocaleTimeString();
const timer = setInterval(() => {
time = new Date().toLocaleTimeString();
}, 1000);
onDestroy(() => clearInterval(timer));
</script>
<p>Current time: {time}</p>
Component composition
Props
Ember Octane
app.hbs
<UserProfile
@name="John"
@age={{20}}
@favouriteColors={{array "green" "blue" "red"}}
@isAvailable={{true}}
/>
Svelte 4
App.svelte
<script>
import UserProfile from "./UserProfile.svelte";
</script>
<UserProfile
name="John"
age={20}
favouriteColors={["green", "blue", "red"]}
isAvailable
/>
Emit to parent
Ember Octane
app.hbs
<p>Are you happy?</p>
<AnswerButton @onYes={{this.handleYes}} @onNo={{this.handleNo}} />
<p style="font-size: 50px;">{{if this.isHappy "😀" "😥"}}</p>
Svelte 4
App.svelte
<script>
import AnswerButton from "./AnswerButton.svelte";
let isHappy = true;
function onAnswerNo() {
isHappy = false;
}
function onAnswerYes() {
isHappy = true;
}
</script>
<p>Are you happy?</p>
<AnswerButton on:yes={onAnswerYes} on:no={onAnswerNo} />
<p style="font-size: 50px;">{isHappy ? "😀" : "😥"}</p>
Slot
Ember Octane
app.hbs
<FunnyButton> Click me! </FunnyButton>
Svelte 4
App.svelte
<script>
import FunnyButton from "./FunnyButton.svelte";
</script>
<FunnyButton>Click me!</FunnyButton>
Slot fallback
Ember Octane
app.hbs
<FunnyButton />
<FunnyButton>I got content!</FunnyButton>
Svelte 4
App.svelte
<script>
import FunnyButton from "./FunnyButton.svelte";
</script>
<FunnyButton />
<FunnyButton>I got content!</FunnyButton>
Context
Ember Octane
app.hbs
<UserProfile />
Svelte 4
App.svelte
<script>
import { setContext } from "svelte";
import UserProfile from "./UserProfile.svelte";
import createUserStore from "./createUserStore.js";
const userStore = createUserStore({
id: 1,
username: "unicorn42",
email: "unicorn42@example.com",
});
setContext("user", userStore);
</script>
<h1>Welcome back, {$userStore.username}</h1>
<UserProfile />
Form input
Input text
Ember Octane
input-hello.hbs
<p>{{this.text}}</p>
<input value={{this.text}} {{on "input" this.handleInput}} />
Svelte 4
InputHello.svelte
<script>
let text = "Hello World";
</script>
<p>{text}</p>
<input bind:value={text} />
Checkbox
Ember Octane
is-available.hbs
<input
id="is-available"
type="checkbox"
checked={{this.isAvailable}}
{{on "change" this.handleChange}}
/>
<label for="is-available">Is available</label>
Svelte 4
IsAvailable.svelte
<script>
let isAvailable = false;
</script>
<input id="is-available" type="checkbox" bind:checked={isAvailable} />
<label for="is-available">Is available</label>
Radio
Ember Octane
pick-pill.hbs
<div>Picked: {{this.picked}}</div>
<input
id="blue-pill"
type="radio"
value="blue"
checked={{eq this.picked "blue"}}
{{on "change" this.handleChange}}
/>
<label htmlFor="blue-pill">Blue pill</label>
<input
id="red-pill"
type="radio"
value="red"
checked={{eq this.picked "red"}}
{{on "change" this.handleChange}}
/>
<label htmlFor="red-pill">Red pill</label>
Svelte 4
PickPill.svelte
<script>
let picked = "red";
</script>
<div>Picked: {picked}</div>
<input id="blue-pill" bind:group={picked} type="radio" value="blue" />
<label for="blue-pill">Blue pill</label>
<input id="red-pill" bind:group={picked} type="radio" value="red" />
<label for="red-pill">Red pill</label>
Select
Ember Octane
color-select.hbs
<select {{on "change" this.select}}>
{{#each this.colors as |color|}}
<option
value={{color.id}}
disabled={{color.isDisabled}}
selected={{eq color.id this.selectedColorId}}
>
{{color.text}}
</option>
{{/each}}
</select>
Svelte 4
ColorSelect.svelte
<script>
let selectedColorId = 2;
const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
{ id: 3, text: "green" },
{ id: 4, text: "gray", isDisabled: true },
];
</script>
<select bind:value={selectedColorId}>
{#each colors as color}
<option value={color.id} disabled={color.isDisabled}>
{color.text}
</option>
{/each}
</select>
Webapp features
Render app
Ember Octane
index.html
<!DOCTYPE html>
<html>
<body>
<div id="app"></div>
<script type="module" src="./app.js"></script>
</body>
</html>
Svelte 4
index.html
<!DOCTYPE html>
<html>
<body>
<div id="app"></div>
<script type="module" src="./app.js"></script>
</body>
</html>
Fetch data
Ember Octane
app.hbs
{{#let (this.fetchUsers) as |request|}}
{{#if request.isLoading}}
<p>Fetching users...</p>
{{else if request.error}}
<p>An error occurred while fetching users</p>
{{else}}
<ul>
{{#each request.users as |user|}}
<li>
<img src={{user.picture.thumbnail}} alt="user" />
<p>{{user.name.first}} {{user.name.last}}</p>
</li>
{{/each}}
</ul>
{{/if}}
{{/let}}
Svelte 4
App.svelte
<script>
import useFetchUsers from "./useFetchUsers";
const { isLoading, error, data: users } = useFetchUsers();
</script>
{#if $isLoading}
<p>Fetching users...</p>
{:else if $error}
<p>An error occurred while fetching users</p>
{:else if $users}
<ul>
{#each $users as user}
<li>
<img src={user.picture.thumbnail} alt="user" />
<p>
{user.name.first}
{user.name.last}
</p>
</li>
{/each}
</ul>
{/if}
Decouvrez plus d’Offres de la plateform ItGalaxy.io :
Découvrez notre gamme complète de services et formations pour accélérer votre carrière.
1. Nous contactez
- Description: Besoin de Formation et des Solutions cloud complètes pour vos applications
- Links:
2. Infra as a Service
- Description: Infrastructure cloud évolutive et sécurisée
- Links:
3. Projets Développeurs
- Description: Découvrez des opportunités passionnantes pour les développeurs
- Links:
4. Développeurs
- Description: Rejoignez notre communauté de développeurs
- Links:
5. Formations Complètes
- Description: Accédez à des formations professionnelles de haute qualité
- Links:
6. Marketplace
- Description: Découvrez notre place de marché de services
- Links:
7. Blogs
- Description: Découvrez nos blogs
- Links:
- comment creer une application mobile ?
- Comment monitorer un site web ?
- Command Checkout in git ?
- Comment git checkout to commit ?
- supprimer une branche git
- dockercoin
- kubernetes c est quoi
- architecture kubernetes
- Installer Gitlab Runner ?
- .gitlab-ci.yml exemples
- CI/CD
- svelte 5 vs solid
- svelte vs lit
- solidjs vs qwik
- alpine vs vue
- Plateform Freelance 2025
- Creation d’un site Web gratuitement
This website is powered by ItGalaxy.io