Shigunaru
A lightweight reactive signals library implemented in Rust.
Features
- Simple reactive signal implementation
- Computed signals with automatic dependency tracking
- Lazy evaluation and caching for computed values
- Subscription-based reactivity system
- Clean and modular API
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
// Create a signal with initial value
let counter = new;
// Use it directly
counter.set;
let value = *counter.get.borrow;
// Subscribe to changes
let counter_effect = counter.clone;
create_effect;
// Change the signal value - will trigger the effect
counter.set;
Computed Signals
Computed signals derive their values from other signals and automatically update when dependencies change:
use ;
// Base signal
let count = new;
// Create a computed signal
let count_for_computed = count.clone;
let doubled = create_computed;
// Initial computed value
assert_eq!;
// Update the source signal
count.set;
// Computed value automatically updates
assert_eq!;
Examples
See the examples directory for more usage examples:
counter.rs- Basic counter with computed values
Run an example with:
Project Structure
shigunaru/
├── src/
│ ├── lib.rs # Main API exports
│ ├── signal.rs # Signal implementation
│ ├── computed.rs # Computed signals
│ ├── effect.rs # Effect system
│ ├── registry.rs # Dependency tracking
│ └── tests/ # Unit tests
├── examples/ # Usage examples
└── tests/ # Integration tests
License
MIT