Protocols
The following protocols are available globally.
-
Protocol that marks something that can be actually dispatched into the
See moreStore
. It doesn’t have any particular requirement, and the protocol is actually used to simply mark a category of items. Currently theStore
is able to manage 2 types ofDispatchable
:SideEffect
,StateUpdater
.Declaration
Swift
public protocol Dispatchable
-
Protocol implemented by a dispatchable that wants to be dispatched in response to a notification
See moreDeclaration
Swift
public protocol NotificationObserverDispatchable : Dispatchable
-
Protocol implemented by a dispatchable that wants to be dispatched in response to a change of the state
See moreDeclaration
Swift
public protocol StateObserverDispatchable : Dispatchable
-
Protocol implemented by a dispatchable that wants to be dispatched in response to the dispatch of another dispatchable
See moreDeclaration
Swift
public protocol DispatchObserverDispatchable : Dispatchable
-
Protocol implemented by a dispatchable that wants to be dispatched when the store starts
See moreDeclaration
Swift
public protocol OnStartObserverDispatchable : Dispatchable
-
Declaration
Swift
public protocol AnySideEffectContext
-
Type erasure for
See moreSideEffect
andReturningSideEffect
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:
See moreprotocol 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) } }
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 useAnySideEffect
.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
See moreAppSideEffect
, you will get better autocompletionDeclaration
Swift
public protocol SideEffect : AnySideEffect
-
Protocol that the side effect dependencies container should implement
See moreDeclaration
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
See moreState
protocol.Declaration
Swift
public protocol State
-
Declaration
Swift
public protocol AnyStateUpdater : Dispatchable
-
A
StateUpdater
is aDispatchable
that can be used to update theStore
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 useAnyStateUpdater
.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
See moreAppStateUpdater
, you will get better autocompletionDeclaration
Swift
public protocol StateUpdater : AnyStateUpdater
-
Declaration
Swift
public protocol AnyStore : AnyObject
-
Entity capable of executing task asynchronously. This can be useful in tests to control asynchronous tasks
See moreDeclaration
Swift
public protocol AsyncProvider