Store

public final class Store<State>
extension Store: ActionDispatcher

The primary container of an application’s state.

The store both contains and mutates the state through a provided reducer as it’s sent actions. Use the didChange publisher to be notified of changes.

  • The current state of the store. Use actions to mutate it.

    Declaration

    Swift

    public private(set) var state: State { get }
  • Subscribe for state changes. It emits the latest action sent to the store.

    Declaration

    Swift

    public let didChange: AnyPublisher<Action, Never>
  • Creates a new store for the given state and reducer.

    Declaration

    Swift

    public init<R, M>(state: State, reducer: R, middleware: M) where State == R.State, R : Reducer, M : Middleware, R.State == M.State
  • Creates a new store for the given state and reducer.

    Declaration

    Swift

    public convenience init<R>(state: State, reducer: R) where State == R.State, R : Reducer
  • Create a proxy of the store for a given type that it adheres to.

    Declaration

    Swift

    @inlinable
    public func proxy<T>(for stateType: T.Type, done: (() -> Void)? = nil) -> StoreProxy<T>?

    Parameters

    stateType

    The type of state for the proxy. This must be a type that the store adheres to.

    done

    A closure called with an async action has completed.

    Return Value

    A proxy object if the state type matches, otherwise nil.

  • Sends an action to the store to mutate its state.

    Declaration

    Swift

    @inlinable
    public func send(_ action: Action)

    Parameters

    action

    The action to mutate the state.