Class Store
A store holds the whole state tree of your application. The only way to change the state inside it is to dispatch an action on it. Your application should only have a single store in a Redux app. As your app grows, instead of adding stores, you split the root reducer into smaller reducers independently operating on the different parts of the state tree.
The store has the following responsibilities:- Holds application state
- Allows access to state via GetState<TState>(string)
- Allows state to be updated via Dispatch(Action)
- Registers listeners via Subscribe<TState>(string, Action<TState>)
- Handles unregistering of listeners via the function returned by Subscribe<TState>(string, Action<TState>)
Here are some important principles you should understand about Reducers:
- Reducers are the only way to update the state.
- Reducers are pure functions that take the previous state and an action, and return the next state.
- Reducers must be pure functions. They should not mutate the state, perform side effects like API calls or routing transitions, or call non-pure functions.
- Reducers must not do asynchronous logic.
- Reducers must not call other Reducer.
- Reducers must not call Subscribe<TState>(string, Action<TState>).
- Reducers must not call GetState<TState>(string)
- Reducers must not call Dispatch(Action)
Inherited Members
Namespace: Unity.AppUI.Redux
Assembly: solution.dll
Syntax
public class Store
Constructors
Name | Description |
---|---|
Store() | Creates a Redux store that holds the complete state tree of your app. |
Methods
Name | Description |
---|---|
CombineReducers(params Reducer[]) | Create a reducer that combines multiple reducers into one. |
CreateAction(string) | Create a new Action. See Unity.AppUI.Redux.Action for more information. |
CreateAction(string, Type) | Create a new Action. See Unity.AppUI.Redux.Action<TPayload> for more information. |
CreateAction<TPayload>(string) | Create a new Action. See Unity.AppUI.Redux.Action<TPayload> for more information. |
CreateReducer<TState>(TState, Action<ReducerSwitchBuilder<TState>>) | Create reducers for a state slice. See SliceReducerSwitchBuilder<TState> for more information. |
CreateSlice<TState>(string, TState, Action<SliceReducerSwitchBuilder<TState>>, Action<ReducerSwitchBuilder<TState>>) | Create a new state slice. A state slice is a part of the state tree. You can provide reducers that will "own" the state slice at the same time. |
Dispatch(string) | Dispatches an action. This is the only way to trigger a state change. |
Dispatch(Action) | Dispatches an action. This is the only way to trigger a state change. |
Dispatch<T>(string, T) | Dispatches an action. This is the only way to trigger a state change. |
GetState() | Returns the current state tree of your application. It is equal to the last value returned by the store's reducer. |
GetState<TState>(string) | Returns the current state tree of your application for a specific slice. It is equal to the last value returned by the store's reducer. |
NotifyStateChanged(string) | Force notify all listeners of a state slice. |
Subscribe<TState>(string, Action<TState>) | Adds a change listener. It will be called any time an action is dispatched, and some part of the state tree may potentially have changed. |