This commit is contained in:
seb
2026-09-19 04:25:01 +02:00
commit 99415ce835
35 changed files with 6807 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { Automat } from '../../lib/index.js';
/**
* Backend API-bound Automat.
*
* Demonstrates:
* 1. Binding to backend API URL via `url: '/api/profile'`.
* 2. Awaiting ready state via `await profileAutomat.ready`.
* 3. React Suspense support via `profileAutomat.read()`.
* 4. Standard subscriber support via `subscribe(this)`.
* 5. Invalidation via `profileAutomat.setDirty()`:
* - Resets state to null (since no defaults were given) or default state.
* - When mounted (subscribers > 0): reloads immediately.
* - When unmounted (subscribers == 0): defers reload until read() or subscribe().
*/
export const profileAutomat = new Automat(
null, // No defaults passed -> resets to null state when set dirty
{
setDirty() {
profileAutomat.setDirty();
},
},
{
name: 'profile',
url: '/api/profile',
}
);