Svelte 5 vs Aurelia 2 comparison

Declare state

Svelte 5

Name.svelte

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

<h1>Hello {name}</h1>

Aurelia 2

name.html

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

name.ts

export class NameCustomElement {
  name = "John";
}

Update state

Svelte 5

Name.svelte

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

<h1>Hello {name}</h1>

Aurelia 2

name.html

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

name.ts

export class NameCustomElement {
  name = "John";

  constructor() {
    this.name = "Jane";
  }
}

Computed state

Svelte 5

DoubleCount.svelte

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

<div>{doubleCount}</div>

Aurelia 2

double-count.html

<div>${doubleCount}</div>

double-count.ts

export class DoubleCountCustomElement {
  count = 10;

  get doubleCount() {
    return this.count * 2;
  }
}

Templating

Minimal template

Svelte 5

HelloWorld.svelte

<h1>Hello world</h1>

Aurelia 2

hello-world.html

<h1>Hello world</h1>

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 2

css-style.html

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

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 2

colors.html

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

colors.ts

export class ColorsCustomElement {
  colors = ["red", "green", "blue"];
}

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 2

counter.html

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

counter.ts

export class CounterCustomElement {
  count = 0;

  incrementCount() {
    this.count++;
  }
}

Dom ref

Svelte 5

InputFocused.svelte

<script>
  let inputElement;

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

<input bind:this={inputElement} />

Aurelia 2

input-focused.html

<input ref="inputElement" />

input-focused.ts

export class InputFocusedCustomElement {
  inputElement: HTMLInputElement;

  attached() {
    this.inputElement.focus();
  }
}

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 2

traffic-light.html

<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>

traffic-light.ts

export class TrafficLightCustomElement {
  private TRAFFIC_LIGHTS = ["red", "orange", "green"];
  private lightIndex = 0;

  get light() {
    return this.TRAFFIC_LIGHTS[this.lightIndex];
  }

  nextLight() {
    this.lightIndex = (this.lightIndex + 1) % this.TRAFFIC_LIGHTS.length;
  }
}

Lifecycle

On mount

Svelte 5

PageTitle.svelte

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

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

Aurelia 2

page-title.html

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

page-title.ts

export class PageTitleCustomElement {
  pageTitle = "";

  attached() {
    this.pageTitle = document.title;
  }
}

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 2

time.html

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

time.ts

export class TimeCustomElement {
  time = new Date().toLocaleTimeString();
  private timer: number;

  attached() {
    this.timer = setInterval(() => {
      this.time = new Date().toLocaleTimeString();
    }, 1000);
  }

  detached() {
    clearInterval(this.timer);
  }
}

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 2

app.html

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

app.ts

export class AppCustomElement {
  name = "John";
  age = 20;
  colors = ["green", "blue", "red"];
  available = true;
}

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 2

app.html

<p>Can I come ?</p>
<answer-button action-handler.bind="handleAnswer"></answer-button>
<p style="font-size: 50px">${isHappy ? "😀" : "😥"}</p>

app.ts

export class AppCustomElement {
  isHappy = true;

  handleAnswer(answer: boolean) {
    this.isHappy = answer;
  }
}

Slot

Svelte 5

App.svelte

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

<FunnyButton>Click me!</FunnyButton>

Aurelia 2

app.html

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

Slot fallback

Svelte 5

App.svelte

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

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

Aurelia 2

app.html

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

Context

Svelte 5

App.svelte

<script>
  import { setContext } from "svelte";
  import UserProfile from "./UserProfile.svelte";
  import createUserState from "./createUserState.svelte.js";

  const user = createUserState({
    id: 1,
    username: "unicorn42",
    email: "unicorn42@example.com",
  });

  setContext("user", user);
</script>

<h1>Welcome back, {user.username}</h1>
<UserProfile />

Aurelia 2

app.html

<h1>Welcome back, ${user.username}</h1>
<user-profile></user-profile>

app.ts

import { IContainer } from "@aurelia/kernel";

export class AppCustomElement {
  user = {
    id: 1,
    username: "unicorn42",
    email: "unicorn42@example.com",
  };

  constructor(@IContainer private container: IContainer) {
    container.register(Registration.instance("user", this.user));
  }
}

Form input

Input text

Svelte 5

InputHello.svelte

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

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

Aurelia 2

input-hello.html

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

input-hello.ts

export class InputHelloCustomElement {
  text = "Hello World";
}

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 2

is-available.html

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

is-available.ts

export class IsAvailableCustomElement {
  isAvailable = false;
}

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 2

pick-pill.html

<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>

pick-pill.ts

export class PickPillCustomElement {
  picked = "red";
}

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 2

color-select.html

<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>

color-select.ts

export class ColorSelectCustomElement {
  selectedColorId = 2;
  colors = [
    { id: 1, text: "red" },
    { id: 2, text: "blue" },
    { id: 3, text: "green" },
    { id: 4, text: "gray", isDisabled: true },
  ];
}

Webapp features

Render app

Svelte 5

index.html

<!DOCTYPE html>
<html>
  <body>
    <div id="app"></div>
    <script type="module" src="./app.js"></script>
  </body>
</html>

Aurelia 2

index.html

<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="./main.ts"></script>
  </head>

  <body>
    <app></app>
  </body>
</html>

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 2

app.html

<template promise.bind="useFetchUsers.fetchData()">
  <p pending>Fetching users...</p>
  <p catch>An error ocurred while fetching users</p>
  <ul then.from-view="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>

app.ts

import { UseFetchUsers } from "./UseFetchUsers";

export class AppCustomElement {
  constructor(private useFetchUsers: UseFetchUsers) {}
}






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