The OSF Angular project uses NGXS as the state management library for Angular applications. NGXS provides a simple, powerful, and TypeScript-friendly framework for managing state across components and services.
The goal of using NGXS is to centralize and streamline the handling of application state, reduce boilerplate, and maintain a predictable flow of data and events throughout the OSF Angular app.
- State: Defines a slice of the application state and how it is modified in response to actions.
- Actions: Dispatched to signal state changes or trigger effects (e.g., API calls).
- Selectors: Functions that extract and transform data from the store.
- Store: Centralized container that holds the application state.
- Effects (via
@ngxs-labs/effectsor@ngxs/store): Side-effect handling such as HTTP requests, logging, etc.
Typical NGXS-related files are organized as follows:
src/app/shared/stores/
└── addons/
├── addons.actions.ts # All action definitions
├── addons.models.ts # Interfaces & data models
├── addons.state.ts # State implementation
├── addons.selectors.ts # Reusable selectors
src/app/shared/services/
└── addons/
├── addons.service.ts # External API calls
The OSF Angular project follows a consistent NGXS state model structure to ensure clarity, predictability, and alignment across all features. The recommended shape for each domain-specific state is as follows:
- Domain state pattern:
domain: {
data: [], // Array of typed model data (e.g., Project[], User[])
isLoading: false, // Indicates if data retrieval (GET) is in progress
isSubmitting: false, // Indicates if data submission (POST/PUT/DELETE) is in progress
error: null, // Captures error messages from failed HTTP requests
}-
dataholds the strongly typed collection of entities defined by the feature's interface or model class. -
isLoadingis a signal used to inform the component and template layer that a read or fetch operation is currently pending. -
isSubmittingsignals that a write operation (form submission, update, delete, etc.) is currently in progress. -
errorstores error state information (commonly strings or structured error objects) that result from failed service interactions. This can be displayed in UI or logged for debugging.
Each domain state should be minimal, normalized, and scoped to its specific feature, mirroring the structure and shape of the corresponding OSF backend API response.
- Redux DevTools is supported. Enable it in development via
NgxsReduxDevtoolsPluginModule. - NGXS Logger Plugin can be used for debugging dispatched actions and state changes.
- NGXS Storage Plugin allows selective persistence of state across reloads.
Refer to the official NGXS documentation for full API details and advanced usage: https://www.ngxs.io/docs
