Skip to content

Commit e0bc653

Browse files
committed
Adds detailed Signal-Memo-Effect model explanation to README
1 parent 84044c3 commit e0bc653

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,39 @@ The next time you access a cached value, it will be recomputed lazily and stored
2323
- Reactive data models
2424
- Computed properties in UI frameworks
2525
- Configuration and build systems
26+
27+
---
28+
29+
### Signal-Memo-Effect Relationship
30+
31+
ReactiveCache is structured around a clear three-tier reactive model:
32+
33+
Signal (atomic mutable)
34+
|
35+
+--> Memo (derived computation, cached value, lazy)
36+
|
37+
+--> Effect (side-effectful computation, eager)
38+
39+
1. **Signal**
40+
Signals are the source of truth in the system. They hold raw values that can change over time.
41+
Updating a signal automatically marks any dependent computations as potentially stale.
42+
43+
2. **Memo**
44+
Memos are derived, computed values that depend on one or more signals (or other memos).
45+
When a signal changes, all memos that depend on it are invalidated.
46+
Accessing a memo after invalidation triggers lazy recomputation, ensuring that cached values are always consistent.
47+
48+
3. **Effect**
49+
Effects are side-effectful computations that run automatically whenever their dependencies change.
50+
They subscribe to signals and memos, reacting to updates without manual intervention.
51+
Effects do not produce cached values; instead, they propagate changes outward (e.g., updating UI, logging, or triggering external events).
52+
53+
**Dependency Flow:**
54+
55+
- **Signals** update their dependents (memos/effects).
56+
- **Memos** recompute lazily when accessed, maintaining up-to-date derived values.
57+
- **Effects** automatically react whenever any dependency they use changes.
58+
59+
This separation ensures efficient and predictable propagation: cached computations are only recomputed when needed, while side effects happen immediately when dependencies change.
60+
61+
This three-level model ensures that changes propagate efficiently, only recomputing what is necessary, and automatically triggering side-effects in a controlled and predictable way.

0 commit comments

Comments
 (0)