StoreType

public protocol StoreType

A protocol that defines storage of an observable state and dispatch methods to modify it. Typically you will implement this on a struct and create a shared instance that you reference throughout your application to get the state or dispatch actions to change it.

Sample store:

struct AppState {
    var id = ObservableProperty(0)
}

struct Store: StoreType {
    var state: ObservableProperty<AppState>
}

let initialState = AppState()
var store = Store(state: ObservableProperty(initialState))
  • The type of the root state of the application.

    Note

    This is inferred from the reduce method implementation.

    Declaration

    Swift

    var state: ObservableState { get set }
  • An observable state of the store. This is accessed directly to subscribe to changes.

    Declaration

    Swift

    typealias ObservableState: ObservablePropertyType
  • dispatch(_:) Default implementation

    Dispatch an action that will mutate the state of the store.

    Default Implementation

    Dispatches an action by settings the state’s value to the result of calling it’s reduce method.

    Dispatches an async action by calling it’s call method.

    Declaration

    Swift

    mutating func dispatch<Action: ActionType where Action.StateValueType == ObservableState.ValueType>(action: Action)
  • Dispatch an async action that when called should trigger another dispatch with a synchronous action.

    Declaration

    Swift

    func dispatch<DynamicAction: DynamicActionType>(action: DynamicAction) -> DynamicAction.ResponseType