Skip to content

Commit 2d213a6

Browse files
martypdxcursoragent
andcommitted
docs: add tooltip example showing instance-scoped state via closure
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 958dc8f commit 2d213a6

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/MENTAL-MODEL.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,53 @@ This seems counterintuitive after years of state-driven frameworks, but Azoth le
4545

4646
**Contrast with other frameworks:** Even SolidJS has quirky non-standard JavaScript behavior arising from transpilation rules. Azoth avoids this by keeping the abstraction layer minimal and aligned with the platform.
4747

48+
#### Real-World Example: Tap-to-Dismiss Tooltips
49+
50+
This production code implements mobile-friendly tooltips with tap-to-dismiss behavior:
51+
52+
```jsx
53+
const StatCard = ({ label, info, value }) => {
54+
// Toggle focus on tap (for mobile dismiss)
55+
// Check on pointerdown BEFORE focus changes, then act on click
56+
let wasFocused = false;
57+
const handlePointerDown = (e) => {
58+
wasFocused = document.activeElement === e.currentTarget;
59+
};
60+
const handleClick = (e) => {
61+
if(wasFocused) {
62+
e.currentTarget.blur();
63+
}
64+
};
65+
66+
return (
67+
<div class="stat-card">
68+
<span class="stat-label" tabindex="0" onpointerdown={handlePointerDown} onclick={handleClick}>
69+
{label}
70+
</span>
71+
<span class="stat-value">{value}</span>
72+
</div>
73+
);
74+
};
75+
```
76+
77+
Notice what's happening:
78+
- `document.activeElement` — native DOM API, just works
79+
- `e.currentTarget.blur()` — real DOM method on the actual element
80+
- `onpointerdown`, `onclick` — direct DOM event listeners, no synthetic events
81+
- Event timing knowledge (pointerdown fires before focus) — standard browser behavior
82+
- **Instance-scoped state**`wasFocused` is local to each component instance via closure
83+
84+
**In React, this would require:**
85+
```jsx
86+
const ref = useRef();
87+
const [isFocused, setIsFocused] = useState(false);
88+
// Plus synthetic event handling
89+
// Plus useEffect for focus management
90+
// Plus careful consideration of re-render timing
91+
```
92+
93+
**With Azoth:** it's just JavaScript and DOM. The framework gets out of the way.
94+
4895
### Philosophy: Filling Gaps, Not Building Abstractions
4996

5097
This is the core philosophical distinction that separates Azoth from other frameworks.

0 commit comments

Comments
 (0)