Classes
The following classes are available globally.
-
An empty dependencies container. It can be used for testing purposes or you don’t need dependencies
See moreDeclaration
Swift
public class EmptySideEffectDependencyContainer : SideEffectDependencyContainer
-
Helper Store type that is used as a partial type.
This type is very helpful when you want to pass the store to pieces of your application that must be aware of the type of state that the app manages but they should not care about the logic part (that is, the dependency container). A very common case is when you want to pass the store to the UI of your application. The UI shouldn’t access to the dependency container directly (it should dispatch a
SideEffect
instead) but you can still have type-safety over the state type that is managed.Warning
you should not create this class directly. The class is meant to be used as a partial type erasure system overStore
-
The
Store
is a sort of single entry point that handles the logic of your application. In Katana, all the various pieces of information that your application manages should be stored in a single atom, called state (see alsoState
protocol).The
Store
, however, doesn’t really implements any application specific logic: this class only manages operations that are requested by the application-specific logic. In particular, you can require theStore
to execute something bydispatching a dispatchable item
.Currently the store handles 2 types of dispatchable:
State Updater
,Side Effect
Update the state
As written before, in Katana every relevant information in the application should be stored in the Store’s state. The only way to update the state is to dispatch a
StateUpdater
. At this point theStore
will execute the following operations:- it executes the interceptors
- it creates the new state, by invoking the
updateState
function of theStateUpdater
- it updates the state
- it resolves the promise
Handle to Business Logic
Non trivial applications require to interact with external services and/or implement complex logics. The proper way to handle these is by dispatching a
SideEffect
. TheStore
will execute the following operations:- it executes the interceptors
- it executes the
SideEffect
body - it resolves the promise
Listen for updates
You can attach a listener that is invoked every time the state changes by using
addListener
.Intercept Dispatchable
It is possible to intercept and reshape the behaviour of the
Store
by using aStoreInterceptor
. AStoreInterceptor
is executed every time something has dispatched, and before it is actually managed by theStore
. Here you implement behaviours like logging, blocking items before they’re executed and even change dynamically which dispatchable items arrive to theStore
itself.See also
StateUpdater
for more information about how to implement an update of the stateSee also
SideEffect
for more information about how to implement a complex/asynchronous logicDeclaration
Swift
open class Store<S, D> : PartialStore<S> where S : State, D : SideEffectDependencyContainer