tansu
Purpose: Tansu is a lightweight, push-based, framework-agnostic state management library inspired by Svelte stores. It extends Svelte's reactive store concepts with additional features like
computed
andbatch
.Key Features:
- Small conceptual surface with expressive and flexible API (functional and class-based).
- Supports both immutable and mutable data.
- Can create "local" (module-level or component-level) collaborating stores.
- Minimal boilerplate, resulting in compact code.
- Tiny implementation (1300 LOC) with no external dependencies.
Core Concepts:
- Writable Stores: Fundamental building block for state management with
set
andupdate
methods. - Derived Stores: Computed from other stores (read-only).
- Computed Stores: Implicitly track dependencies and optimize re-computations.
- Batch Updates: Defer synchronous subscriber calls to avoid intermediate inconsistent states.
- Utilities:
asReadable
,asWritable
, andget
for enhanced store manipulation.
- Writable Stores: Fundamental building block for state management with
Target Audience:
- Developers looking for a simple, efficient state management solution.
- Framework-agnostic but works well with Svelte (fully compatible) and Angular (supports DI and
AsyncPipe
).
Comparison with Svelte Stores:
- Fixes issues like the "asymmetric diamond dependency problem."
- Adds
batch
for synchronized state updates. - Offers more granular control over derived and computed stores.
Framework Integration:
- Svelte: Fully compatible, retains Svelte's reactive store API.
- Angular: Works seamlessly with Angular's dependency injection and
AsyncPipe
. Stores can interoperate with RxJS observables.
For more details, check the Tansu API documentation .
agnosticangularcomputedderivedinteropmodelobservablereactivereadablesignalsignalsstatestate-managementstoresveltewritable
Featured Stories
No featured articles here. Navigate to an article, then pick the Feature on menu button