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 more

    Declaration

    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 over Store
    See more

    Declaration

    Swift

    open class PartialStore<S> : AnyStore where S : State
  • 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 also State 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 the Store to execute something by dispatching 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 the Store will execute the following operations:

    • it executes the interceptors
    • it creates the new state, by invoking the updateState function of the StateUpdater
    • 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. The Store 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 a StoreInterceptor. A StoreInterceptor is executed every time something has dispatched, and before it is actually managed by the Store. Here you implement behaviours like logging, blocking items before they’re executed and even change dynamically which dispatchable items arrive to the Store itself.

    See also

    StateUpdater for more information about how to implement an update of the state

    See also

    SideEffect for more information about how to implement a complex/asynchronous logic
    See more

    Declaration

    Swift

    open class Store<S, D> : PartialStore<S> where S : State, D : SideEffectDependencyContainer