Svelte 5 vs Aurelia 1 comparison

Declare state

Svelte 5

Name.svelte

<script>
  let name = $state("John");
</script>

<h1>Hello {name}</h1>

Aurelia 1

name.html

<template>
  <h1>Hello ${name}</h1>
</template>

Update state

Svelte 5

Name.svelte

<script>
  let name = $state("John");
  name = "Jane";
</script>

<h1>Hello {name}</h1>

Aurelia 1

name.html

<template>
  <h1>Hello ${name}</h1>
</template>

Computed state

Svelte 5

DoubleCount.svelte

<script>
  let count = $state(10);
  const doubleCount = $derived(count * 2);
</script>

<div>{doubleCount}</div>

Aurelia 1

double-count.html

<template>
  <div>${doubleCount}</div>
</template>

Templating

Minimal template

Svelte 5

HelloWorld.svelte

<h1>Hello world</h1>

Aurelia 1

hello-world.html

<template>
  <h1>Hello world</h1>
</template>

Styling

Svelte 5

CssStyle.svelte

<h1 class="title">I am red</h1>
<button style="font-size: 10rem;">I am a button</button>

<style>
  .title {
    color: red;
  }
</style>

Aurelia 1

css-style.css

.title {
  color: red;
}

Loop

Svelte 5

Colors.svelte

<script>
  const colors = ["red", "green", "blue"];
</script>

<ul>
  {#each colors as color (color)}
    <li>{color}</li>
  {/each}
</ul>

Aurelia 1

colors.html

<template>
  <ul>
    <li repeat.for="color of colors">${color}</li>
  </ul>
</template>

Event click

Svelte 5

Counter.svelte

<script>
  let count = $state(0);

  function incrementCount() {
    count++;
  }
</script>

<p>Counter: {count}</p>
<button onclick={incrementCount}>+1</button>

Aurelia 1

counter.html

<template>
  <p>Counter: ${count}</p>
  <button click.trigger="incrementCount()">+1</button>
</template>

Dom ref

Svelte 5

InputFocused.svelte

<script>
  let inputElement;

  $effect(() => {
    inputElement.focus();
  });
</script>

<input bind:this={inputElement} />

Aurelia 1

input-focused.html

<template>
  <input ref="inputElement" />
</template>

Conditional

Svelte 5

TrafficLight.svelte

<script>
  const TRAFFIC_LIGHTS = ["red", "orange", "green"];
  let lightIndex = $state(0);

  const light = $derived(TRAFFIC_LIGHTS[lightIndex]);

  function nextLight() {
    lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length;
  }
</script>

<button onclick={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>

Aurelia 1

traffic-light.html

<template>
  <button click.trigger="nextLight()">Next light</button>
  <p>Light is: ${light}</p>
  <p>
    You must
    <span if.bind="light === 'red'">STOP</span>
    <span if.bind="light === 'orange'">SLOW DOWN</span>
    <span if.bind="light === 'green'">GO</span>
  </p>
</template>

Lifecycle

On mount

Svelte 5

PageTitle.svelte

<script>
  let pageTitle = $state("");
  $effect(() => {
    pageTitle = document.title;
  });
</script>

<p>Page title: {pageTitle}</p>

Aurelia 1

page-title.html

<template>
  <p>Page title is: ${pageTitle}</p>
</template>

On unmount

Svelte 5

Time.svelte

<script>
  let time = $state(new Date().toLocaleTimeString());

  $effect(() => {
    const timer = setInterval(() => {
      time = new Date().toLocaleTimeString();
    }, 1000);

    return () => clearInterval(timer);
  });
</script>

<p>Current time: {time}</p>

Aurelia 1

time.html

<template>
  <p>Current time: ${time}</p>
</template>

Component composition

Props

Svelte 5

App.svelte

<script>
  import UserProfile from "./UserProfile.svelte";
</script>

<UserProfile
  name="John"
  age={20}
  favouriteColors={["green", "blue", "red"]}
  isAvailable
/>

Aurelia 1

app.html

<template>
  <require from="./user-profile"></require>
  <user-profile
    name.bind="name"
    age.bind="age"
    favourite-colors.bind="colors"
    is-available.bind="available"
  ></user-profile>
</template>

Emit to parent

Svelte 5

App.svelte

<script>
  import AnswerButton from "./AnswerButton.svelte";

  let isHappy = $state(true);

  function onAnswerNo() {
    isHappy = false;
  }

  function onAnswerYes() {
    isHappy = true;
  }
</script>

<p>Are you happy?</p>
<AnswerButton onYes={onAnswerYes} onNo={onAnswerNo} />
<p style="font-size: 50px;">{isHappy ? "😀" : "😥"}</p>

Aurelia 1

app.html

<template>
  <require from="./answer-button"></require>
  <p>Can I come ?</p>
  <answer-button action-handler.call="handleAnswer(reply)"></answer-button>
  <p style="font-size: 50px">${isHappy ? "😀" : "😥"}</p>
</template>

Slot

Svelte 5

App.svelte

<script>
  import FunnyButton from "./FunnyButton.svelte";
</script>

<FunnyButton>Click me!</FunnyButton>

Aurelia 1

app.html

<template>
  <require from="./funny-button"></require>

  <funny-button>Click me !</funny-button>
</template>

Slot fallback

Svelte 5

App.svelte

<script>
  import FunnyButton from "./FunnyButton.svelte";
</script>

<FunnyButton />
<FunnyButton>I got content!</FunnyButton>

Aurelia 1

app.html

<template>
  <require from="./funny-button"></require>

  <funny-button></funny-button>
  <funny-button>Click me !</funny-button>
</template>

Form input

Input text

Svelte 5

InputHello.svelte

<script>
  let text = $state("Hello World");
</script>

<p>{text}</p>
<input bind:value={text} />

Aurelia 1

input-hello.html

<template>
  <p>${text}</p>
  <input value.bind="text" />
</template>

Checkbox

Svelte 5

IsAvailable.svelte

<script>
  let isAvailable = $state(false);
</script>

<input id="is-available" type="checkbox" bind:checked={isAvailable} />
<label for="is-available">Is available</label>

Aurelia 1

is-available.html

<template>
  <input id="is-available" type="checkbox" checked.bind="isAvailable" />
  <label for="is-available">Is available</label>: ${isAvailable}
</template>

Radio

Svelte 5

PickPill.svelte

<script>
  let picked = $state("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>

Aurelia 1

pick-pill.html

<template>
  <div>Picked: ${picked}</div>

  <input id="blue-pill" checked.bind="picked" type="radio" value="blue" />
  <label for="blue-pill">Blue pill</label>

  <input id="red-pill" checked.bind="picked" type="radio" value="red" />
  <label for="red-pill">Red pill</label>
</template>

Select

Svelte 5

ColorSelect.svelte

<script>
  let selectedColorId = $state(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>

Aurelia 1

color-select.html

<template>
  <select value.bind="selectedColorId">
    <option value="">Select A Color</option>
    <option
      repeat.for="color of colors"
      value.bind="color.id"
      disabled.bind="color.isDisabled"
    >
      ${color.text}
    </option>
  </select>
</template>

Webapp features

Fetch data

Svelte 5

App.svelte

<script>
  import useFetchUsers from "./useFetchUsers.svelte.js";

  const response = useFetchUsers();
</script>

{#if response.isLoading}
  <p>Fetching users...</p>
{:else if response.error}
  <p>An error occurred while fetching users</p>
{:else if response.users}
  <ul>
    {#each response.users as user}
      <li>
        <img src={user.picture.thumbnail} alt="user" />
        <p>
          {user.name.first}
          {user.name.last}
        </p>
      </li>
    {/each}
  </ul>
{/if}

Aurelia 1

app.html

<template>
  <p if.bind="isLoading">Fetching users...</p>
  <p if.bind="error">An error ocurred while fetching users</p>
  <ul if.bind="users">
    <li repeat.for="user of users">
      <img src.bind="user.picture.thumbnail" alt="user" />
      <p>${ user.name.first } ${ user.name.last }</p>
    </li>
  </ul>
</template>






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


4. Développeurs


5. Formations Complètes


6. Marketplace

7. Blogs


This website is powered by ItGalaxy.io