Zum Inhalt springen

Store as Application Facade

Ein Store, der nur Daten hält und CRUD-Operationen anbietet, ist ein Cache. Ein Store, der Applikationslogik orchestriert und Zustandsübergänge kapselt, ist eine Applikationsfassade.

Cache-StoreApplication-Facade-Store
setTasks(tasks)loadTasksForProject(projectId)
setLoading(true)Intern verwaltet
Komponente ruft HTTP direktStore koordiniert alles
export const TasksStore = signalStore(
withState<TasksState>({ tasks: [], status: 'idle' }),
withMethods((store) => ({
async loadForProject(projectId: string) {
patchState(store, { status: 'loading' });
try {
const tasks = await inject(TasksService).getByProject(projectId);
patchState(store, { tasks, status: 'success' });
} catch (e) {
patchState(store, { status: 'error' });
}
},
})),
);
  • Alle asynchronen Operationen (API-Calls, Subscriptions)
  • Alle Zustandsübergänge (loading → success → error)
  • Alle Command-Aggregationen (mehrere API-Calls für einen Use-Case)
  • Alle Error-Handling-Strategien

Nur Signals. Nur fertig gemappte ViewModels. Keine Promises, keine Observables, keine HTTP.