The definitive state management solution for Leptos applications - featuring stores, state machines, middleware, and DevTools integration.
- ๐ช Reactive Stores - Zustand-inspired API with Leptos integration
- ๐ฏ State Machines - XState-like state machines with guards and actions
- ๐ Middleware System - Extensible middleware for logging, validation, and more
- ๐ ๏ธ DevTools Integration - Browser DevTools for state inspection and debugging
- ๐พ Persistence - Automatic state persistence with multiple storage backends
- ๐ Visualization - State machine diagrams and transition tracking
- ๐งช Testing Framework - Comprehensive testing utilities for state machines
- โก Performance Optimized - Minimal overhead with smart reactivity
- ๐ WASM Ready - Full WebAssembly support for web applications
[dependencies]
leptos-state = "0.2.0"
leptos = "0.8"
use leptos_state::{create_store, use_store};
#[derive(Clone, Debug)]
struct CounterStore {
count: i32,
name: String,
}
impl CounterStore {
fn increment(&mut self) {
self.count += 1;
}
fn set_name(&mut self, name: String) {
self.name = name;
}
}
fn Counter() -> impl IntoView {
let (store, actions) = use_store::<CounterStore>();
view! {
<div>
<h2>"Counter: " {store.count}</h2>
<p>"Name: " {store.name}</p>
<button on:click=move |_| actions.increment()>
"Increment"
</button>
</div>
}
}
use leptos_state::{MachineBuilder, use_machine};
#[derive(Clone, Debug)]
enum TrafficLightEvent {
Next,
Emergency,
}
fn TrafficLight() -> impl IntoView {
let machine = MachineBuilder::new()
.state("red")
.on(TrafficLightEvent::Next, "green")
.state("green")
.on(TrafficLightEvent::Next, "yellow")
.state("yellow")
.on(TrafficLightEvent::Next, "red")
.initial("red")
.build();
let (state, send) = use_machine(machine);
view! {
<div>
<h2>"Traffic Light: " {state.value()}</h2>
<button on:click=move |_| send(TrafficLightEvent::Next)>
"Next Light"
</button>
</div>
}
}
- ๐ User Guide - Comprehensive usage guide
- ๐ง API Reference - Complete API documentation
- ๐ Examples - Working code samples
- ๐ Migration Guide - Upgrade from v0.1.0
- First-class Leptos integration - Built specifically for Leptos applications
- Reactive by design - Automatic updates when state changes
- WASM optimized - Designed for web applications
- Familiar APIs - Inspired by Zustand and XState
- Type safety - Full Rust type safety and compile-time guarantees
- Performance - Minimal runtime overhead with smart optimizations
- Middleware ecosystem - Extensible architecture for enterprise needs
- DevTools support - Professional debugging and monitoring
- Testing utilities - Comprehensive testing framework included
use leptos_state::{LoggerMiddleware, ValidationMiddleware, MiddlewareChain};
let store = create_store::<MyStore>()
.with_middleware(
MiddlewareChain::new()
.add(LoggerMiddleware::new())
.add(ValidationMiddleware::new())
);
let machine = MachineBuilder::new()
.state("idle")
.build_with_persistence(PersistenceConfig {
enabled: true,
storage_key: "my_machine".to_string(),
auto_save: true,
..Default::default()
});
let generator = machine.build_with_code_generation(CodeGenConfig {
target_languages: vec![ProgrammingLanguage::Rust, ProgrammingLanguage::TypeScript],
output_directory: "generated".to_string(),
..Default::default()
});
generator.generate_code()?;
Check out our comprehensive examples:
- ๐ฑ Todo App - Full-featured todo application
- ๐ฆ Traffic Light - State machine basics
- ๐ Analytics Dashboard - Complex state management
- ๐ง Code Generation - Multi-language code generation
-
Add to your project:
cargo add leptos-state
-
Check out the examples:
git clone https://github.com/cloud-shuttle/leptos-state.git cd leptos-state/examples cargo run --bin counter
-
Read the documentation:
We welcome contributions! Please see our Contributing Guide for details.
- ๐ Report bugs on GitHub Issues
- ๐ก Request features via GitHub Discussions
- ๐ Submit PRs for bug fixes and improvements
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
- Built with โค๏ธ for the Leptos community
- Inspired by Zustand and XState
- Part of the Cloud Shuttle ecosystem
Ready to build amazing Leptos applications? Get started now!