Skip to content

Guide

This guide provides a step-by-step approach to setting up Stately, from initial installation to production-ready configurations.

The documentation is organized by task:

  • Start with a single store.
  • Add plugins to solve specific state challenges.
  • Implement SSR-safe patterns for SvelteKit.
  • Use the reference pages for detailed API contracts.

Installation

sh
pnpm add @selfagency/stately svelte

Defining Your First Store

To get started, create a state manager and a store definition, then instantiate the store:

ts
import { createStateManager, defineStore } from '@selfagency/stately';

const manager = createStateManager();

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  getters: {
    doubleCount(state) {
      return state.count * 2;
    }
  },
  actions: {
    increment() {
      this.count += 1;
    }
  }
});

const counter = useCounterStore(manager);
counter.increment();

Core Concepts

Adding Advanced Behavior

  • Plugins — A guide to selecting and implementing plugins.
  • State Machines (FSM) — Model explicit workflows and state transitions.
  • Validation — Ensure state consistency by rejecting invalid updates.

SSR & SvelteKit

Tooling & Maintenance

Migration


Documentation Strategy

  • Use the Guide when you want to understand recommended patterns and architectural trade-offs.
  • Use the API Reference when you need exact option shapes, function signatures, or TypeScript definitions.

Released under the MIT License.