Skip to main content

Overview

Svelte Atoms Core uses a unique Bond Architecture for state management. Bonds are self-contained state objects that communicate through Svelte’s context system, providing predictable and type-safe state management.

Svelte 5 Runes

All components leverage Svelte 5’s new reactivity system with runes:

State with $state

Create reactive state that automatically updates the UI:

Derived State with $derived

Compute values that automatically update when dependencies change:

Effects with $effect

Run side effects when state changes:

Understanding Bonds

Bonds are the core state management abstraction in Svelte Atoms Core. They encapsulate component state and provide a consistent interface for state access and manipulation.

What is a Bond?

A Bond is a class that extends the base Bond class:
Bonds provide:
  • State management - Reactive state with Svelte 5 runes
  • Element references - Access to DOM elements
  • Context-based communication - Share state between components
  • Lifecycle management - Setup and cleanup

Accessing Component Bonds

Components expose their bond through snippets:

Bond State Properties

Each bond has a state property that provides access to component state:

Component State Patterns

Controlled Components

Control component state from parent:

Uncontrolled Components

Let components manage their own state:

Custom State Management

Using filterDropdownData

The filterDropdownData utility creates reactive filtered state:
filterDropdownData returns an object with:
  • query - Current search query (get/set)
  • current - Filtered results (reactive)

Custom Runes

Svelte Atoms Core provides custom runes for common patterns:

State Management Best Practices

1

Use $state for local reactive state

Keep component-local state simple with $state runes:
2

Use $derived for computed values

Avoid manual updates by deriving values:
3

Access bonds through snippets

Get component state through the bond parameter:
4

Use bind: for two-way binding

Keep parent and component state in sync:

Advanced Bond Usage

Custom Bond Factories

Create custom bonds for specialized behavior:

Next Steps

Using Components

Learn component composition patterns

Customization

Customize components with variants

TypeScript

Type-safe state management

API Reference

Full API documentation