Class SwitchBuilder<TBuilder, TState>
Base implementation of a switch statement builder to generate a reducer.
Implements
Inherited Members
Namespace: Unity.AppUI.Redux
Assembly: Unity.AppUI.Redux.dll
Syntax
public class SwitchBuilder<TBuilder, TState> : ISwitchBuilder<TBuilder, TState> where TBuilder : SwitchBuilder<TBuilder, TState>
Type Parameters
Name | Description |
---|---|
TBuilder | The type of the builder. |
TState | The type of the state. |
Fields
m_ActionTypes
The action types that are already handled.
Declaration
protected readonly HashSet<string> m_ActionTypes
Field Value
Methods
AddCase(IActionCreator, Reducer<TState>)
Adds a case to the reducer switch statement.
Declaration
public virtual TBuilder AddCase(IActionCreator actionCreator, Reducer<TState> reducer)
Parameters
Type | Name | Description |
---|---|---|
IAction |
actionCreator | The action creator for the action type you want to handle. |
Reducer<TState> | reducer | The reducer function for the action type you want to handle. |
Returns
Type | Description |
---|---|
TBuilder | The builder instance to chain calls. |
AddCase<TPayload>(IActionCreator<TPayload>, Reducer<TPayload, TState>)
Adds a case to the reducer switch statement.
Declaration
public virtual TBuilder AddCase<TPayload>(IActionCreator<TPayload> actionCreator, Reducer<TPayload, TState> reducer)
Parameters
Type | Name | Description |
---|---|---|
IAction |
actionCreator | The action creator for the action type you want to handle. |
Reducer<TPayload, TState> | reducer | The reducer function for the action type you want to handle. |
Returns
Type | Description |
---|---|
TBuilder | The builder instance to chain calls. |
Type Parameters
Name | Description |
---|---|
TPayload | The type of the action payload. |
GetActionCreators()
Create a dictionary of action creator per action type.
Declaration
public virtual Dictionary<string, IActionCreator> GetActionCreators()
Returns
Type | Description |
---|---|
Dictionary<string, IAction |
The dictionary of action creators. |
GetReducer()
Get the reducer output function.
Declaration
public Reducer<TState> GetReducer()
Returns
Type | Description |
---|---|
Reducer<TState> | The reducer function. |
ValidateCase(IActionCreator, object)
Validates the case to ensure it is not a duplicate.
Declaration
protected virtual void ValidateCase(IActionCreator actionCreator, object reducer)
Parameters
Type | Name | Description |
---|---|---|
IAction |
actionCreator | The action creator. |
object | reducer | The reducer. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown if the action creator or reducer is null. |
Invalid |
Thrown if the action type is already handled. |