Structures
The following structures are available globally.
-
Erases the protocol
See moreMiddleware
. Please check its documentation for more information.Declaration
Swift
public struct AnyMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol
-
ActionHandler
defines a protocol for entities able to handle actions - defined by the associated typeActionType
andAnyActionHandler
erases this protocol to a generic struct type.The only protocol requirement is a function that allows other entities to dispatch actions, so Views (or Presenters, ViewModels) in your UI layer, or even Middlewares can create actions of a certain type and send to your store, that is generalized by this protocol.
See moreDeclaration
Swift
public struct AnyActionHandler<ActionType> : ActionHandler
-
Representation of the entity responsible for creating and dispatching the action, including information useful for logging, debugging, analytics or monitoring. The action source will be implicitly created when
ActionHandler.dispatch
is called from a middleware, view or presenter, and it will contain the file, function and line from where the dispatch function was called. Additionally you can append extra information useful for debugging, as an optional String attached to the ActionSource.The Action Source will arrive at every middleware’s
See morehandle
function, and you have the opportunity to use this information when performing side- effects, such as printing logs.Declaration
Swift
public struct ActionSource : Codable, Hashable
-
Wraps an action and the information about its dispatcher. It can be used when reactive pipelines want to enforce that the result is an action while keeping track about the source of that action. For example, certain RxSwift, Combine or ReactiveSwift pipeline want to send actions to the store and because ActionHandler has a function
See moredispatch(_ action: ActionType, from dispatcher: ActionSource)
, that pipeline should output aDispatchedAction<Action>
to fulfil everything needed by the ActionHandler to feed that action into the store.Declaration
Swift
public struct DispatchedAction<Action>
extension DispatchedAction: Decodable where Action: Decodable
extension DispatchedAction: Encodable where Action: Encodable
extension DispatchedAction: Equatable where Action: Equatable
extension DispatchedAction: Hashable where Action: Hashable
-
AnyStateProvider
erases the protocolStateProvider
, which defines a entities able to offer state publishers (Combine Publisher, RxSwift Observable, ReactiveSwift SignalProducer) of certainStateType
, so everybody can observe the global state changes through this container. Usually aStore
will implement that, but it can also be aStoreProjection
with a state that is derived from the global source-of-truth.The only protocol requirement is to offer a property
See morestatePublisher
that will allow other entities to subscribe to state changes and react to those.Declaration
Swift
public struct AnyStateProvider<StateType> : StateProvider
-
A MiddlewareReader is a way to lazily inject dependencies into a Middleware. For example, you may want to compose multiple middlewares but from a library, and in this library you don’t have the dependencies to inject just yet, because these dependencies are only present in the main target. That way, instead of creating the middlewares (which would require all the dependencies), you can wrap their initializers in a MiddlewareReader. The middleware reader is not a middleware, is a a factory (in OOP terms) from
See more(Dependencies) -> MiddlewareType
(in FP approach). The benefit of wrapping the middleware initializers in a MiddlewareReader is that, for all means, MiddlewareReaders can be composed as Middlewares, can be lifted as Middlewares, but all of this without in fact creating the Middlewares. Your library can then expose a single MiddlewareReader as public, and you keep all its middlewares as internal classes. From the main target you compose this MiddlewareReader with other MiddlewareReaders coming from other libraries and from the main target itself. Somewhere where you create the Store, you finally inject the dependencies at once and you materialize all your middlewares at the same time. Remember that “inject then compose” is the same as “compose then inject”, but while the former needs dependencies upfront, the latter is more flexible for being lazy. For those familiar with Functional Programming, this is similar to Reader Monad, but as SwiftRex recommends dependencies only on Middlewares, this Reader works specifically with Middlewares.Declaration
Swift
public struct MiddlewareReader<Dependencies, MiddlewareType> : MiddlewareReaderProtocol where MiddlewareType : MiddlewareProtocol
extension MiddlewareReader: Semigroup where MiddlewareType: Semigroup
extension MiddlewareReader: Monoid where MiddlewareType: Monoid
-
Wraps a closure that will be called after the Reducer pipeline has changed the state with the current action. With this structure, a middleware can schedule some callback to be executed with the new state, and evidently access this state to check what’s different. This can be very useful for Middlewares that perform logging, monitoring or telemetry, so you can check the state before and after reducers’ execution, or how much time it took for the whole chain to be called (in case this middleware is the first in the chain, of course).
See moreAfterReducer
is a monoid, that means it can be combined with anotherAfterReducer
to form a new one (that executes both operations in the reverse order) and an identity instance, that when combined with any otherAfterReducer
changes nothing in the result, acting as a neutral element in composition. The identity of anAfterReducer
is the static instancedoNothing()
, that contains an empty closure for no-op. The combination between twoAfterReducer
instances occur in reverse order so the first middleware will have its “after reducer” closure executed last. This composition can be achieved by using the operator<>
Declaration
Swift
@available(*, deprecated, message: "Use `MiddlewareProtocol` instead of `Middleware`. It doesn't use `AfterReducer`. This struct will be removed on 1.0.") public struct AfterReducer : Monoid
-
A very eager scheduler that will perform tasks in the Main Queue, immediately if possible.
If current queue is MainQueue, it will behave like
See moreImmediateScheduler
(https://developer.apple.com/documentation/combine/immediatescheduler) and perform the task immediately in the current RunLoop. If the queue is different, then it will schedule to the Main Dispatch Queue and perform as soon as its new RunLoop starts (depending on the DispatchQueue.SchedulerOptions provided). UseASAPScheduler.default
in order to use this Scheduler.Declaration
Swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public struct ASAPScheduler
extension ASAPScheduler: Scheduler
-
Undocumented
See moreDeclaration
Swift
public struct ElementIDAction<ID, Action> where ID : Hashable
extension ElementIDAction: Identifiable
extension ElementIDAction: Decodable where ID: Decodable, Action: Decodable
extension ElementIDAction: Encodable where ID: Encodable, Action: Encodable
extension ElementIDAction: Equatable where Action: Equatable
extension ElementIDAction: Hashable where Action: Hashable
-
Undocumented
See moreDeclaration
Swift
public struct ElementIndexAction<Index, Action> where Index : Comparable
extension ElementIndexAction: Decodable where Index: Decodable, Action: Decodable
extension ElementIndexAction: Encodable where Index: Encodable, Action: Encodable
extension ElementIndexAction: Equatable where Index: Equatable, Action: Equatable
extension ElementIndexAction: Hashable where Index: Hashable, Action: Hashable
-
Abstraction over subscriber/observer types from reactive frameworks. This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and delegating to them once the wrapper funcions are called.
See moreDeclaration
Swift
public struct SubscriberType<Element, ErrorType> where ErrorType : Error
-
Abstraction over publisher/observable/signal producer types from reactive frameworks. This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and delegating to them once the wrapper funcions are called.
See moreDeclaration
Swift
public struct PublisherType<Element, ErrorType> where ErrorType : Error
-
Abstraction over passthrough subject types (
See morePassthroughSubject
,PublishSubject
,Signal
) from reactive frameworks. This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and delegating to them once the wrapper funcions are called.Declaration
Swift
public struct SubjectType<Element, ErrorType> where ErrorType : Error
-
Abstraction over subject types able to keep the last object (
See moreCurrentValueSubject
,BehaviorSubject
,MutableProperty
,Variable
) from reactive frameworks. This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and delegating to them once the wrapper funcions are called.Declaration
Swift
public struct ReplayLastSubjectType<Element, ErrorType> where ErrorType : Error
-
The
ComposedMiddleware
is a container of inner middlewares that are chained together in the order as they were composed. Whenever anEventProtocol
or anActionProtocol
arrives to be handled by thisComposedMiddleware
, it will delegate to its internal chain of middlewares.It could be initialized manually by using the
init()
and configured by using the methodappend(middleware:)
, but if you’re ok with using custom operators you can compose two or more middlewares using the diamond operator:
See morelet composedMiddleware = firstMiddleware <> secondMiddleware <> thirdMiddleware
Declaration
Swift
public struct ComposedMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol
extension ComposedMiddleware: Monoid
-
The
See moreIdentityMiddleware
won’t do any operation, simply bypass actions through. It’s meant to provide identity axiom to middleware type to allow its conformance to monoid algebra. It will simply forward actions to the next middleware in the chain or to the reducers. It can be useful for Unit Tests or for some compositions.Declaration
Swift
public struct IdentityMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol, Equatable
-
This is a container that lifts a sub-state middleware to a global state middleware.
Internally you find the middleware responsible for handling events and actions for a sub-state (
Part
), while this outer class will be able to compose with global state (Whole
) in yourStore
.You should not be able to instantiate this class directly, instead, create a middleware for the sub-state and call
See moreMiddleware.lift(_:)
, passing as parameter the keyPath from whole to part.Declaration
Swift
public struct LiftMiddleware<GlobalInputActionType, GlobalOutputActionType, GlobalStateType, PartMiddleware> : MiddlewareProtocol where PartMiddleware : MiddlewareProtocol
-
This is a container that lifts a sub-state middleware to a global state middleware.
Internally you find the middleware responsible for handling events and actions for a sub-state (
Part
), while this outer class will be able to compose with global state (Whole
) in yourStore
.You should not be able to instantiate this class directly, instead, create a middleware for the sub-state and call
See moreMiddleware.liftToCollection(_:)
, passing as parameter the keyPath from whole to part.Declaration
Swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public struct LiftToCollectionMiddleware< GlobalInputActionType, GlobalOutputActionType, GlobalStateType, CollectionState: MutableCollection, PartMiddleware: MiddlewareProtocol>: MiddlewareProtocol where PartMiddleware.StateType: Identifiable, CollectionState.Element == PartMiddleware.StateType