Defining your Main Application State

When building an application using Redux, the first thing to think about is,"What state do I want to store?" It is generally a good idea to capture allof the application's state so that it can be accessible from anywhere and all in one place for easy inspection.

In the application state, we store things like:

  • Data received through API calls
  • User input
  • Presentation state, such as menu and button toggles
  • Application preferences
  • Internationalization messages
  • Themes and other customizable areas of your application
    To define your application state, use an interface called AppState or IAppState, depending on the naming conventions used on your project.

Here's an example:

app/models/appState.ts

  1. export interface AppState {
  2. readonly colors: Colors;
  3. readonly localization: Localization;
  4. readonly login: Login;
  5. readonly projectList: ProjectList;
  6. readonly registration: Registration;
  7. readonly showMainNavigation: boolean;
  8. }
Note: We're using readonly to ensure compile-time immutability, and itprovides the simplest immutable implementation without adding more dependencies to clutter the examples. However, feel free to use another approach on yourproject that makes sense for your team.

原文: https://angular-2-training-book.rangle.io/handout/state-management/ngrx/defining_your_main_application_state.html