Store

public final class Store<State> where State : Decodable, State : Encodable

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
  • Subscribe for state changes. It emits the latest action sent to the store.

    Declaration

    Swift

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

    Declaration

    Swift

    public init<R>(state: State, reducer: R, middleware: [Middleware<State>] = []) where State == R.State, R : Reducer
  • Sends an action to the store to mutate its state.

    Declaration

    Swift

    public func send(_ action: Action)

    Parameters

    action

    The action to mutate the state.

  • Create a new ActionDispatcher that acts as a proxy between the action sender and the store. It optionally allows actions to be modified or tracked.

    Declaration

    Swift

    public func proxy(modifyAction: ActionModifier? = nil, sentAction: ((Action) -> Void)? = nil) -> ActionDispatcher

    Return Value

    a new action dispatcher.