StoreType
public protocol StoreType : ActionHandler, StateProvider
A protocol that defines the two expected roles of a “Store”: receive/distribute actions (ActionHandler
); and publish changes of the the
current app state (StateProvider
) to possible subscribers. It can be a real store (such as ReduxStoreBase
) or just a “proxy” that acts on
behalf of a real store, for example, in the case of StoreProjection
.
-
projection(action:
Extension methodstate: ) Creates a subset of the current store by applying any transformation to the State or Action types.
Declaration
Swift
public func projection<ViewAction, ViewState>( action viewActionToGlobalAction: @escaping (ViewAction) -> ActionType?, state globalStateToViewState: @escaping (StateType) -> ViewState ) -> StoreProjection<ViewAction, ViewState>
Parameters
action
a closure that will transform the View Actions into global App Actions, to be dispatched in the original Store
state
a closure that will transform the global App State into the View State, to subscribe the original Store and drive the View upon changes
Return Value
a
StoreProjection
struct, that uses the original Store under the hood, by applying the required transformations on state and action when app state changes or view actions arrive. It doesn’t store anything, just proxies the original store. -
eraseToAnyStoreType()
Extension methodType-erasure for the protocol
StoreType
.For more information please check the protocol documentation.
Declaration
Swift
public func eraseToAnyStoreType() -> AnyStoreType<ActionType, StateType>
Return Value
a type-erased store (
AnyStoreType
) from the currentStoreType
-
contramapAction(_:
Extension method) Create another
StoreType
that handles a different type of Action. The original store will be used behind the scenes, by only the provided “transform” closure whenever an action arrives.Declaration
Swift
public func contramapAction<NewActionType>(_ transform: @escaping (NewActionType) -> ActionType) -> AnyStoreType<NewActionType, StateType>
Parameters
transform
a closure that will be executed every time an action arrives at the proxy
StoreType
, so we can map it into the expected action type of the originalStoreType
.Return Value
an
AnyStoreType
with sameStatetype
but differentActionType
than the original store. -
mapState(_:
Extension method) Create another
StoreType
that handles a different type of State. The original store will be used behind the scenes, by only applying the provided “transform” closure whenever the state changes in the original store.Declaration
Swift
public func mapState<NewStateType>(_ transform: @escaping (StateType) -> NewStateType) -> AnyStoreType<ActionType, NewStateType>
Parameters
transform
a closure that will be executed every time the state changes in the original store, so we can map it into the state type expected by the subscribers of the proxy
StoreType
.Return Value
an
AnyStoreType
with sameActionType
but differentStateType
than the original store.