StoreProxy

public struct StoreProxy<State> : ActionDispatcher

Creates a proxy of the store object for use by middleware.

Middleware may use the store proxy to retreive the current state, send actions, continue to the next middleware, or subscribe to store changes. With the proxy, middleware don’t have to worry about retaining the store. Instead, the proxy provides a safe API to access a weak reference to it.

  • Emits after the specified action was sent to the store.

    Declaration

    Swift

    public var didChange: AnyPublisher<Action, Never>
  • Retrieves the latest state from the store.

    Declaration

    Swift

    public var state: State { get }
  • Send an action to the store.

    Declaration

    Swift

    @inlinable
    public func send(_ action: Action)

    Parameters

    action

    The action to send

  • Use this in middleware to send an action to the next step in the pipeline. Outside of middleware, it does nothing.

    Declaration

    Swift

    @inlinable
    public func next(_ action: Action)

    Parameters

    action

    The action to send

  • Used by action plans to tell the store that a publisher has completed or cancelled its work. Only use this if the action plan is not returning a publisher or subscribing via ActionSubscriber. This is not needed by action plans that don’t return a cancellable.

    Declaration

    Swift

    @inlinable
    public func done()