Class StoreExtensions
Extensions for the IDispatchable.
Inherited Members
Namespace: Unity.AppUI.Redux
Assembly: Unity.AppUI.Redux.dll
Syntax
public static class StoreExtensions
Methods
Dispatch(IDispatchable, string)
Dispatches an action. This is the only way to trigger a state change.
Declaration
public static void Dispatch(this IDispatchable store, string actionType)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
string | actionType | The type of the action. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the actionType is null or empty. |
Dispatch(IDispatchable, ActionCreator)
Dispatches an action from the given creator. This is a shortcut to call the creator and dispatch the action.
Declaration
public static void Dispatch(this IDispatchable store, ActionCreator creator)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
Action |
creator | The action creator. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the creator is null. |
DispatchAsyncThunkCoroutine<TPayload, TArg>(IDispatchable, AsyncThunkAction<TPayload, TArg>, CancellationToken)
Dispatches an async thunk action.
This method will dispatch the pending action, then call the thunk, and finally dispatch the fulfilled or rejected action based on the result of the thunk.
Declaration
public static Coroutine DispatchAsyncThunkCoroutine<TPayload, TArg>(this IDispatchable store, AsyncThunkAction<TPayload, TArg> asyncThunkAction, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
Async |
asyncThunkAction | The async thunk action to dispatch. |
Cancellation |
cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Coroutine | The coroutine. |
Type Parameters
Name | Description |
---|---|
TPayload | The type of the payload (the result of the thunk). |
TArg | The type of the argument to pass to the thunk. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the asyncThunkAction is null. |
DispatchAsyncThunk<TPayload, TArg>(IDispatchable, AsyncThunkAction<TPayload, TArg>, CancellationToken)
Dispatches an async thunk action.
This method will dispatch the pending action, then call the thunk, and finally dispatch the fulfilled or rejected action based on the result of the thunk.
Declaration
public static Task DispatchAsyncThunk<TPayload, TArg>(this IDispatchable store, AsyncThunkAction<TPayload, TArg> asyncThunkAction, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
Async |
asyncThunkAction | The async thunk action to dispatch. |
Cancellation |
cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
Type Parameters
Name | Description |
---|---|
TPayload | The type of the payload (the result of the thunk). |
TArg | The type of the argument to pass to the thunk. |
Remarks
Dispatching an async thunk action with this method invloves the use of async/await.
If your target platform doesn't support async/await, you can use
Dispatch
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the asyncThunkAction is null. |
Dispatch<TPayload>(IDispatchable, string, TPayload)
Dispatches an action. This is the only way to trigger a state change.
Declaration
public static void Dispatch<TPayload>(this IDispatchable store, string actionType, TPayload payload)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
string | actionType | The type of the action. |
TPayload | payload | The payload of the action. |
Type Parameters
Name | Description |
---|---|
TPayload | The type of the payload. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the actionType is null or empty. |
Dispatch<TPayload>(IDispatchable, ActionCreator<TPayload>, TPayload)
Dispatches an action from the given creator with a payload. This is a shortcut to call the creator and dispatch the action.
Declaration
public static void Dispatch<TPayload>(this IDispatchable store, ActionCreator<TPayload> creator, TPayload payload)
Parameters
Type | Name | Description |
---|---|---|
IDispatchable | store | The store to dispatch the action to. |
Action |
creator | The action creator. |
TPayload | payload | The payload of the action. |
Type Parameters
Name | Description |
---|---|
TPayload | The type of the payload. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the creator is null. |
GetState<TSliceState>(IStateProvider<IPartionableState>, string)
Get the state of a slice.
Declaration
public static TSliceState GetState<TSliceState>(this IStateProvider<IPartionableState> store, string sliceName)
Parameters
Type | Name | Description |
---|---|---|
IState |
store | The store. |
string | sliceName | The name of the slice. |
Returns
Type | Description |
---|---|
TSlice |
The state of the slice. |
Type Parameters
Name | Description |
---|---|
TSliceState | The type of the slice state. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Argument |
Thrown when the sliceName is null or empty. |
GetState<TSliceState, TSelected>(IStateProvider<IPartionableState>, string, Selector<TSliceState, TSelected>)
Get the selected part of the state in a slice.
Declaration
public static TSelected GetState<TSliceState, TSelected>(this IStateProvider<IPartionableState> store, string sliceName, Selector<TSliceState, TSelected> selector)
Parameters
Type | Name | Description |
---|---|---|
IState |
store | The store. |
string | sliceName | The name of the slice. |
Selector<TSliceState, TSelected> | selector | The selector to get the selected part of the state. |
Returns
Type | Description |
---|---|
TSelected | The selected part of the state. |
Type Parameters
Name | Description |
---|---|
TSliceState | The type of the slice state. |
TSelected | The type of the selected part of the state. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when any of the arguments is null. |
GetState<TState, TSelected>(IStateProvider<TState>, Selector<TState, TSelected>)
Get a selected part of the state.
Declaration
public static TSelected GetState<TState, TSelected>(this IStateProvider<TState> store, Selector<TState, TSelected> selector)
Parameters
Type | Name | Description |
---|---|---|
IState |
store | The store. |
Selector<TState, TSelected> | selector | The selector to get the selected part of the state. |
Returns
Type | Description |
---|---|
TSelected | The selected part of the state. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state. |
TSelected | The type of the selected part of the state. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown when the store is null. |
Subscribe<TStoreState>(INotifiable<TStoreState>, Listener<TStoreState>, SubscribeOptions<TStoreState>)
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.
Declaration
public static IDisposableSubscription Subscribe<TStoreState>(this INotifiable<TStoreState> store, Listener<TStoreState> listener, SubscribeOptions<TStoreState> options = default)
Parameters
Type | Name | Description |
---|---|---|
INotifiable<TStoreState> | store | The store. |
Listener<TStoreState> | listener | A callback to be invoked on every dispatch. |
Subscribe |
options | The options for the subscription. |
Returns
Type | Description |
---|---|
IDisposable |
A Subscription object that can be disposed. |
Type Parameters
Name | Description |
---|---|
TStoreState | The type of the store state. |
Remarks
This method doesn't check for duplicate listeners, so calling it multiple times with the same listener will result in the listener being called multiple times.
Exceptions
Type | Condition |
---|---|
Argument |
Thrown if the listener is null. |
Subscribe<TStoreState, TSliceState>(INotifiable<TStoreState>, string, Listener<TSliceState>, SubscribeOptions<TSliceState>)
Subscribe to a state change and listen to a specific part of the state.
Declaration
public static IDisposableSubscription Subscribe<TStoreState, TSliceState>(this INotifiable<TStoreState> store, string sliceName, Listener<TSliceState> listener, SubscribeOptions<TSliceState> options = default) where TStoreState : IPartionableState
Parameters
Type | Name | Description |
---|---|---|
INotifiable<TStoreState> | store | The store. |
string | sliceName | The name of the slice. |
Listener<TSliceState> | listener | The listener to be invoked on state change. |
Subscribe |
options | The options for the subscription. |
Returns
Type | Description |
---|---|
IDisposable |
A Subscription object that can be disposed. |
Type Parameters
Name | Description |
---|---|
TStoreState | The type of the store state. |
TSliceState | The type of the slice state. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown if the store is null. |
Argument |
Thrown if the slice name is null or empty. |
Argument |
Thrown if the listener is null. |
Subscribe<TStoreState, TSelected, TSliceState>(INotifiable<TStoreState>, string, Selector<TSliceState, TSelected>, Listener<TSelected>, SubscribeOptions<TSelected>)
Subscribe to a state change and listen to a specific part of the state in a slice.
Declaration
public static IDisposableSubscription Subscribe<TStoreState, TSelected, TSliceState>(this INotifiable<TStoreState> store, string sliceName, Selector<TSliceState, TSelected> selector, Listener<TSelected> listener, SubscribeOptions<TSelected> options = default) where TStoreState : IPartionableState
Parameters
Type | Name | Description |
---|---|---|
INotifiable<TStoreState> | store | The store. |
string | sliceName | The name of the slice. |
Selector<TSliceState, TSelected> | selector | The selector to get the selected part of the state. |
Listener<TSelected> | listener | The listener to be invoked on state change. |
Subscribe |
options | The options for the subscription. |
Returns
Type | Description |
---|---|
IDisposable |
A Subscription object that can be disposed. |
Type Parameters
Name | Description |
---|---|
TStoreState | The type of the store state. |
TSelected | The type of the selected part of the state. |
TSliceState | The type of the slice state. |
Exceptions
Type | Condition |
---|---|
Argument |
Thrown if the store is null. |
Argument |
Thrown if the slice name is null or empty. |
Argument |
Thrown if the selector is null. |
Argument |
Thrown if the listener is null. |