svelte-mini-dashboard Svelte Themes

Svelte Mini Dashboard

Mini dashboard built with Svelte to explore compile-time reactivity and alternative frontend paradigms

๐Ÿš€ Svelte Mini Dashboard

Exploring Svelte to understand alternative frontend paradigms.

Project Day 7 - fokus pada eksplorasi paradigma frontend dengan Svelte.

๐Ÿ“š Table of Contents

๐ŸŽฏ Tentang Project

Svelte Mini Dashboard adalah aplikasi web sederhana yang dibangun untuk memahami paradigma compile-time reactivity dari Svelte. Project ini bukan sekadar membuat UI, tapi lebih fokus pada eksplorasi konsep-konsep fundamental yang membedakan Svelte dari framework lain seperti React atau Vue.

Tujuan Utama:

  • Memahami reactivity tanpa Virtual DOM
  • Eksplorasi compile-time vs runtime approach
  • Belajar state management yang lebih natural
  • Mengalami DX (Developer Experience) yang berbeda

๐Ÿ’ก Kenapa Svelte?

Sebagai backend developer yang sedang eksplor frontend, saya memilih Svelte karena:

1. Compile-Time Magic

Svelte adalah compiler, bukan framework runtime. Saat build, Svelte mengubah component menjadi vanilla JavaScript yang highly optimized. Browser hanya load hasil compile, tanpa framework overhead.

// Yang kamu tulis (Svelte)
let count = 0;
$: doubled = count * 2;

// Yang di-compile jadi vanilla JS (simplified)
let count = 0;
let doubled = 0;
function update_count() {
  doubled = count * 2;
  update_dom();
}

2. Reactivity Bawaan

Tidak perlu useState, setState, atau hooks yang kompleks:

<!-- Svelte -->
<script>
  let count = 0;
  $: doubled = count * 2; // Auto reactive!
</script>

<button on:click={() => count++}>
  {count} (doubled: {doubled})
</button>

Bandingkan dengan React:

const [count, setCount] = useState(0);
const doubled = count * 2; // Re-compute every render

<button onClick={() => setCount(count + 1)}>
  {count} (doubled: {doubled})
</button>

3. Less Boilerplate

Svelte punya syntax yang lebih ringkas dan intuitif:

  • Two-way binding: bind:value={text}
  • Scoped CSS tanpa setup
  • No virtual DOM diffing
  • Smaller bundle size

4. Performance by Default

  • Surgical DOM updates (tahu persis element mana yang perlu update)
  • No runtime overhead
  • Smaller bundle size
  • Faster initial load

โœจ Fitur

1. Counter Component

  • โž• Increment & โž– Decrement button
  • ๐Ÿ”„ Real-time reactive update
  • ๐Ÿ“Š Computed value (double count)
  • โš ๏ธ Conditional warning (count > 10)

Konsep: Reactive statement, conditional rendering

2. Dark Mode Toggle

  • ๐ŸŒ™ Switch Light/Dark theme
  • ๐Ÿ’พ LocalStorage persistence
  • ๐ŸŽจ Smooth transition animation
  • ๐Ÿ”„ State sync across refresh

Konsep: Event dispatcher, lifecycle hooks, localStorage

3. Dynamic Card List

  • โž• Add new cards dynamically
  • ๐Ÿ—‘๏ธ Remove cards
  • ๐Ÿ“‹ List rendering with key
  • ๐Ÿ“Š Real-time card count

Konsep: Reactive arrays, list rendering, two-way binding

๐Ÿ› ๏ธ Teknologi

Technology Version Purpose
Svelte 4.0+ Frontend framework (compiler)
Vite 5.0+ Build tool & dev server
JavaScript ES6+ Programming language
CSS 3 Styling (scoped)

Tidak menggunakan:

  • โŒ TypeScript (keep it simple)
  • โŒ CSS Framework (Tailwind, Bootstrap, etc)
  • โŒ State management library (Redux, Zustand)
  • โŒ React (fokus ke Svelte paradigm)

๐Ÿ“ฆ Instalasi

Prerequisites

  • Node.js 18+
  • npm atau yarn

Setup Project

# Clone repository
git clone https://github.com/yourusername/svelte-mini-dashboard.git
cd svelte-mini-dashboard

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

Buka browser di http://localhost:5173

๐Ÿ“ Struktur Project

svelte-mini-dashboard/
โ”œโ”€โ”€ public/                 # Static assets
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ Counter.svelte       # Counter component
โ”‚   โ”‚   โ”œโ”€โ”€ ThemeToggle.svelte   # Dark mode toggle
โ”‚   โ”‚   โ””โ”€โ”€ CardList.svelte      # Dynamic card list
โ”‚   โ”œโ”€โ”€ App.svelte              # Root component
โ”‚   โ””โ”€โ”€ main.js                 # Entry point
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ vite.config.js
โ””โ”€โ”€ README.md

Component Breakdown

Counter.svelte

<script>
  let count = 0;
  $: doubled = count * 2; // Reactive statement
</script>

<button on:click={() => count++}>+</button>

Konsep:

  • Simple assignment untuk reactivity
  • Reactive statement dengan $:
  • Conditional rendering dengan {#if}

ThemeToggle.svelte

<script>
  import { createEventDispatcher } from 'svelte';
  const dispatch = createEventDispatcher();
  
  function toggle() {
    dispatch('themeChange', { isDark });
  }
</script>

Konsep:

  • Event dispatcher untuk parent-child communication
  • Lifecycle hooks (onMount)
  • LocalStorage integration

CardList.svelte

<script>
  let cards = [...];
  $: cardCount = cards.length; // Auto computed
</script>

{#each cards as card (card.id)}
  <div>{card.title}</div>
{/each}

Konsep:

  • List rendering dengan {#each}
  • Two-way binding dengan bind:value
  • Reactive arrays

๐Ÿง  Konsep yang Dipelajari

1. Reactivity Otomatis

Di Svelte, assignment biasa = reactive update:

let count = 0;
count = count + 1; // Auto update UI!

Di React, harus pakai setState:

const [count, setCount] = useState(0);
setCount(count + 1); // Manual state management

2. Reactive Statements ($:)

Kode yang otomatis re-run saat dependency berubah:

$: doubled = count * 2; // Re-run when count changes

$: if (count > 10) {
  console.log('High count!');
}

$: {
  // Multiple statements
  localStorage.setItem('count', count);
  document.title = `Count: ${count}`;
}

React equivalent: useEffect dengan dependency array.

3. Two-Way Binding

<!-- Svelte: 1 line -->
<input bind:value={name} />

<!-- React: 3 lines -->
<input 
  value={name}
  onChange={(e) => setName(e.target.value)}
/>

4. Scoped CSS

CSS otomatis scoped ke component tanpa CSS-in-JS:

<style>
  button {
    background: blue; /* Only affects this component */
  }
</style>

5. No Virtual DOM

Svelte compile component jadi kode yang:

  1. Tahu persis elemen mana yang perlu update
  2. Update DOM secara surgical
  3. Tidak perlu diffing algorithm

Flow:

  • React: State change โ†’ Virtual DOM โ†’ Diffing โ†’ Real DOM
  • Svelte: State change โ†’ Direct DOM update (pre-compiled)

6. Event Handling

<!-- Inline -->
<button on:click={() => count++}>+</button>

<!-- Function -->
<button on:click={handleClick}>+</button>

<!-- Event modifiers -->
<button on:click|preventDefault={handleClick}>Submit</button>

โš–๏ธ Svelte vs React

Aspek Svelte React
Paradigm Compiler (compile-time) Library (runtime)
Reactivity Assignment biasa (count++) useState, setState
Bundle Size Kecil (~5-10KB) Besar (~40KB + deps)
Learning Curve Mudah (less abstraction) Sedang (hooks, closure)
Performance Surgical DOM updates Virtual DOM diffing
State Management Built-in stores External (Redux, Zustand)
Styling Scoped CSS bawaan Butuh library (styled-components)
Ecosystem Kecil tapi growing Sangat besar
Job Market Emerging Dominan
Use Case Small-medium apps Enterprise apps

Compile-Time vs Runtime

Svelte (Compile-Time):

Write Component โ†’ Svelte Compiler โ†’ Optimized JS โ†’ Browser
                   (Build time)      (No framework overhead)

React (Runtime):

Write Component โ†’ Browser loads React โ†’ Runtime reconciliation
                  (~40KB library)     (Virtual DOM diffing)

Analogi:

  • Svelte: Meal prep (masakan sudah jadi, tinggal panaskan)
  • React: Restaurant (chef masak real-time)

๐Ÿ’ญ Insights & Learnings

โœ… Yang Bikin Wow

  1. Natural Reactivity

    • Tidak perlu mikir state management
    • Code lebih readable dan intuitive
    • Less mental overhead
  2. DX (Developer Experience)

    • Fast refresh sangat cepat
    • Error messages sangat jelas
    • Less boilerplate = lebih produktif
  3. Performance Bawaan

    • Tidak perlu useMemo, useCallback, React.memo
    • Bundle size kecil
    • Load time lebih cepat
  4. Simplicity

    • Closer ke vanilla JavaScript
    • No hooks rules to remember
    • Easier untuk backend dev

โš ๏ธ Trade-offs

  1. Ecosystem Lebih Kecil

    • Third-party libraries masih terbatas
    • Community resources less abundant
    • Debugging tools kurang mature
  2. Job Market

    • Lowongan kerja masih didominasi React
    • Team adoption lebih lambat
    • Learning resource kurang banyak
  3. Complex State

    • Untuk app ultra-complex, butuh Svelte stores
    • Global state management kurang established pattern

๐ŸŽ“ Kesimpulan

Kapan Pakai Svelte:

  • โœ… App kecil-menengah dengan focus pada performance
  • โœ… Prototype/MVP yang butuh fast iteration
  • โœ… Project dengan bundle size constraint
  • โœ… Developer baru belajar frontend
  • โœ… Static site dengan interactivity ringan

Kapan Pakai React:

  • โœ… App ultra-complex dengan banyak state
  • โœ… Team sudah heavily invested di React
  • โœ… Butuh ecosystem library yang matang
  • โœ… Enterprise app dengan long-term maintenance

๐Ÿ”ฎ Final Thoughts

Svelte adalah game changer untuk developer yang:

  • Datang dari backend dan bingung dengan React complexity
  • Ingin fokus ke logic, bukan boilerplate
  • Butuh performance without extra effort
  • Appreciate simplicity over ecosystem size

Quote yang cocok:

"Svelte makes you feel like you're writing vanilla JavaScript, but with superpowers."

๐Ÿ“ธ Screenshots

Light Mode

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        ๐Ÿš€ Svelte Mini Dashboard             โ”‚
โ”‚     Exploring compile-time reactivity       โ”‚
โ”‚              โ˜€๏ธ Light Mode                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿ“Š Counter       โ”‚  โ”‚ ๐ŸŽด Card List         โ”‚
โ”‚                  โ”‚  โ”‚                      โ”‚
โ”‚       42         โ”‚  โ”‚ Total Cards: 5       โ”‚
โ”‚   Double: 84     โ”‚  โ”‚                      โ”‚
โ”‚                  โ”‚  โ”‚ [Add form]           โ”‚
โ”‚  [ โˆ’ ] [Reset]   โ”‚  โ”‚                      โ”‚
โ”‚       [ + ]      โ”‚  โ”‚ โšก Reactive           โ”‚
โ”‚                  โ”‚  โ”‚ ๐Ÿ”จ Compiled          โ”‚
โ”‚ โš ๏ธ Count is high!โ”‚  โ”‚ ๐ŸŽฏ Minimal           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Dark Mode

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        ๐Ÿš€ Svelte Mini Dashboard             โ”‚
โ”‚     Exploring compile-time reactivity       โ”‚
โ”‚              ๐ŸŒ™ Dark Mode                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
[Dark theme with #1a1a1a background]

๐Ÿค Kontribusi

Contributions are welcome! Project ini adalah learning project, jadi feel free untuk:

  • ๐Ÿ› Report bugs
  • ๐Ÿ’ก Suggest features
  • ๐Ÿ“ Improve documentation
  • ๐ŸŽจ Enhance UI/UX
  • ๐Ÿงช Add tests
  • โ™ฟ Improve accessibility

Cara Kontribusi

  1. Fork repository ini
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push ke branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

Kontribusi Ideas

Beberapa ide improvement yang bisa dikontribusikan:

  1. Add Unit Tests - Testing dengan Vitest
  2. Add Animation - Svelte transitions & animations
  3. Accessibility - ARIA labels, keyboard navigation
  4. TypeScript - Migrate ke TypeScript
  5. More Components - Modal, Toast notification, etc
  6. State Management - Implement Svelte stores
  7. Responsive Design - Better mobile experience
  8. Performance Monitoring - Add performance metrics
  9. Documentation - JSDoc comments
  10. CI/CD - GitHub Actions workflow

๐Ÿ“„ License

MIT License - feel free to use this project for learning!

๐Ÿ™ Acknowledgments

  • Svelte - Amazing framework/compiler
  • Vite - Lightning fast build tool
  • Anthropic Claude - AI pair programming
  • Fullstack 7 Day Roadmap Challenge

๐Ÿ“š Resources

Official Docs

Learning Resources

Next Steps

  • ๐Ÿ“ฆ Try SvelteKit (meta-framework, like Next.js)
  • ๐Ÿ—„๏ธ Learn Svelte Stores (global state)
  • ๐ŸŽจ Explore Svelte Animations (built-in transitions)
  • ๐Ÿš€ Build real project!

Made with โค๏ธ by [Yogiexc]
Day 7/7 - Fullstack Roadmap Challenge

โญ Star this repo if you found it helpful!
๐Ÿฆ Share your learnings on Twitter with #SvelteLearning

Top categories

Loading Svelte Themes