Structures

The following structures are available globally.

  • Erases the protocol Middleware. Please check its documentation for more information.

    See more

    Declaration

    Swift

    public struct AnyMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol
  • IO

    Undocumented

    See more

    Declaration

    Swift

    public struct IO<OutputActionType>
    extension IO: Monoid
  • Reducer is a pure function wrapped in a monoid container, that takes an action and the current state to calculate the new state.

    See more

    Declaration

    Swift

    public struct Reducer<ActionType, StateType>
    extension Reducer: Monoid
  • ActionHandler defines a protocol for entities able to handle actions - defined by the associated type ActionType and AnyActionHandler 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 more

    Declaration

    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 handle function, and you have the opportunity to use this information when performing side- effects, such as printing logs.

    See more

    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 dispatch(_ action: ActionType, from dispatcher: ActionSource), that pipeline should output a DispatchedAction<Action> to fulfil everything needed by the ActionHandler to feed that action into the store.

    See more

    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 protocol StateProvider, which defines a entities able to offer state publishers (Combine Publisher, RxSwift Observable, ReactiveSwift SignalProducer) of certain StateType, so everybody can observe the global state changes through this container. Usually a Store will implement that, but it can also be a StoreProjection with a state that is derived from the global source-of-truth.

    The only protocol requirement is to offer a property statePublisher that will allow other entities to subscribe to state changes and react to those.

    See more

    Declaration

    Swift

    public struct AnyStateProvider<StateType> : StateProvider
  • Type-erasure for the protocol StoreType.

    For more information please check the protocol documentation. The easiest way of creating this type is calling StoreType/eraseToAnyStoreType() on any store type.

    See more

    Declaration

    Swift

    public struct AnyStoreType<ActionType, StateType> : StoreType
  • 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 (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.

    See more

    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). AfterReducer is a monoid, that means it can be combined with another AfterReducer to form a new one (that executes both operations in the reverse order) and an identity instance, that when combined with any other AfterReducer changes nothing in the result, acting as a neutral element in composition. The identity of an AfterReducer is the static instance doNothing(), that contains an empty closure for no-op. The combination between two AfterReducer 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 <>

    See more

    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 ImmediateScheduler (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). Use ASAPScheduler.default in order to use this Scheduler.

    See more

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public struct ASAPScheduler
    extension ASAPScheduler: Scheduler
  • Undocumented

    See more

    Declaration

    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 more

    Declaration

    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 more

    Declaration

    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 more

    Declaration

    Swift

    public struct PublisherType<Element, ErrorType> where ErrorType : Error
  • Abstraction over passthrough subject types (PassthroughSubject, 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.

    See more

    Declaration

    Swift

    public struct SubjectType<Element, ErrorType> where ErrorType : Error
  • Abstraction over subject types able to keep the last object (CurrentValueSubject, 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.

    See more

    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 an EventProtocol or an ActionProtocol arrives to be handled by this ComposedMiddleware, it will delegate to its internal chain of middlewares.

    It could be initialized manually by using the init() and configured by using the method append(middleware:), but if you’re ok with using custom operators you can compose two or more middlewares using the diamond operator:

    let composedMiddleware = firstMiddleware <> secondMiddleware <> thirdMiddleware
    
    See more

    Declaration

    Swift

    public struct ComposedMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol
    extension ComposedMiddleware: Monoid
  • The IdentityMiddleware 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.

    See more

    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 your Store.

    You should not be able to instantiate this class directly, instead, create a middleware for the sub-state and call Middleware.lift(_:), passing as parameter the keyPath from whole to part.

    See more

    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 your Store.

    You should not be able to instantiate this class directly, instead, create a middleware for the sub-state and call Middleware.liftToCollection(_:), passing as parameter the keyPath from whole to part.

    See more

    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