Protocols

The following protocols are available globally.

  • Protocol that marks something that can be actually dispatched into the Store. It doesn’t have any particular requirement, and the protocol is actually used to simply mark a category of items. Currently the Store is able to manage 2 types of Dispatchable: SideEffect, StateUpdater.

    See more

    Declaration

    Swift

    public protocol Dispatchable
  • Protocol implemented by a dispatchable that wants to be dispatched in response to a notification

    See more

    Declaration

    Swift

    public protocol NotificationObserverDispatchable : Dispatchable
  • Protocol implemented by a dispatchable that wants to be dispatched in response to a change of the state

    See more

    Declaration

    Swift

    public protocol StateObserverDispatchable : Dispatchable
  • Protocol implemented by a dispatchable that wants to be dispatched in response to the dispatch of another dispatchable

    See more

    Declaration

    Swift

    public protocol DispatchObserverDispatchable : Dispatchable
  • Protocol implemented by a dispatchable that wants to be dispatched when the store starts

    See more

    Declaration

    Swift

    public protocol OnStartObserverDispatchable : Dispatchable
  • Type erasure for SideEffectContext

    See more

    Declaration

    Swift

    public protocol AnySideEffectContext
  • Declaration

    Swift

    public protocol AnySideEffect : Dispatchable
  • A AnySideEffect that is capable of returning a typed value.

    In order to promote reusability of the logic written using this type, both the state and the dependencies are erased. This helps tremendously when writing libraries and generic logic, and it can also be extended to be used in the apps.

    For example, if the app needs to use a typed returning side effect it can define something like:

    protocol AppReturningSideEffect: ReturningSideEffect {
      typealias StateType = AppState
      typealias Dependencies = AppDependencies
    
      func sideEffect(_ context: SideEffectContext<StateType, Dependencies>) throws -> ReturnType
    }
    
    extension AppReturningSideEffect {
      func sideEffect(_ context: AnySideEffectContext) throws -> ReturnValue {
        guard let typedContext = context as? SideEffectContext<StateType, Dependencies> else {
          fatalError("Invalid context passed to side effect")
        }
    
        return try self.sideEffect(typedContext)
      }
    }
    
    See more

    Declaration

    Swift

    public protocol ReturningSideEffect : AnySideEffect
  • A side effect is a single atom of the logic of your application. While you can actually use them as you desire, the idea is to implement in each side effect a meaningful, self contained, piece of logic that can be used from other pieces of you application (e.g., dispatched by a View Controller or by another side effect).

    The SideEffect is strongly tied to the state that it handles and the dependencies it has. This greatly simplifies the code written in normal situations. However, if you need to create updaters that are not strictly tied to a concrete types (e.g., in a library) you can use AnySideEffect.

    App Tips & Tricks

    To further simplify the usage of a SideEffect you can add to your application a helper protocol

    /// assuming `AppState` is the type of your application's state and `DependenciesContainer` is the
    /// container of your dependencies
    protocol AppSideEffect: SideEffect where StateType == AppState, Dependencies == DependenciesContainer {}
    

    By conforming to AppSideEffect, you will get better autocompletion

    See more

    Declaration

    Swift

    public protocol SideEffect : AnySideEffect
  • Protocol that the side effect dependencies container should implement

    See more

    Declaration

    Swift

    public protocol SideEffectDependencyContainer : AnyObject
  • Protocol for the state of the applications. In Katana, all the relevant application information should be placed in a single struct that has to implement the State protocol.

    See more

    Declaration

    Swift

    public protocol State
  • Type erasure for StateUpdater

    See also

    StateUpdater
    See more

    Declaration

    Swift

    public protocol AnyStateUpdater : Dispatchable
  • A StateUpdater is a Dispatchable that can be used to update the Store state configuration.

    The StateUpdater is strongly tied to the state that it handles. This greatly simplifies the code written in normal situations. However, if you need to create updaters that are not strictly tied to a concrete state type (e.g., in a library) you can use AnyStateUpdater.

    App Tips & Tricks

    To additionally simplify the usage of a StateUpdater you can add to your application an helper protocol

    /// assuming `AppState` is the type of your application's state
    protocol AppStateUpdater: StateUpdater where StateType == AppState {}
    

    By conforming to AppStateUpdater, you will get better autocompletion

    See more

    Declaration

    Swift

    public protocol StateUpdater : AnyStateUpdater
  • Type Erasure for Store

    See more

    Declaration

    Swift

    public protocol AnyStore : AnyObject
  • Entity capable of executing task asynchronously. This can be useful in tests to control asynchronous tasks

    See more

    Declaration

    Swift

    public protocol AsyncProvider