Explicit state management

From andresdiegolanda/design-first-ai · View interactive version

Explicit state management is an AI agent skill from the GitHub repository andresdiegolanda/design-first-ai. Loading/error/empty state pattern for HTTP data. Use when a component loads data and must show loading, error, and empty states.

How to use this skill

Skill file

Skill: Explicit State Management (angular-user-search)

The pattern — three explicit state properties

items: Item[] = [];
loading = false;
error: string | null = null;

private loadItems(): void {
  this.loading = true;
  this.error = null;
  this.itemService.getItems().pipe(
    takeUntil(this.destroy$)
  ).subscribe({
    next: (items) => { this.items = items; this.loading = false; },
    error: (err) => {
      this.error = 'Failed to load items. Please try again.';
      this.loading = false;
      console.error('[ComponentName]: failed to load items', err);
    }
  });
}

Template state blocks (mutually exclusive)

<div *ngIf="loading">Loading…</div>
<div *ngIf="error && !loading">{{ error }} <button (click)="retry()">Retry</button></div>
<div *ngIf="!loading && !error && items.length === 0">No results.</div>
<ul *ngIf="!loading && !error && items.length > 0">...</ul>

Rules

Design Constraints

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.