ActionBinder

public struct ActionBinder

Binds a state to a setter based action for use by controls that expect a two-way binding value such as TextFields. This is useful for simple actions that are expected to be dispatched many times a second. It should be avoided by any complicated or asynchronous actions.

func map(state: AppState, binder: StateBinder) -> Props? {
  Props(
    todos: state.todos,
    orderBy: binder.bind(state.orderBy) { TodoListAction.setOrderBy($0) }
  )
}
  • Create a binding between a given state and an action.

    Declaration

    Swift

    @inlinable
    public func bind<T>(_ state: T, dispatch getAction: @escaping (T) -> Action?) -> ActionBinding<T> where T : Equatable

    Parameters

    state

    The state to retrieve.

    getAction

    Given a new version of the state, it returns an action to dispatch.

    Return Value

    A new Binding object.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind(_ getAction: @escaping () -> Action?) -> ActionBinding<() -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0>(_ getAction: @escaping (P0) -> Action?) -> ActionBinding<(P0) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0, P1>(_ getAction: @escaping (P0, P1) -> Action?) -> ActionBinding<(P0, P1) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0, P1, P2>(
      _ getAction: @escaping (P0, P1, P2) -> Action?
    ) -> ActionBinding<(P0, P1, P2) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0, P1, P2, P3>(
      _ getAction: @escaping (P0, P1, P2, P3) -> Action?
    ) -> ActionBinding<(P0, P1, P2, P3) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0, P1, P2, P3, P4>(
      _ getAction: @escaping (P0, P1, P2, P3, P4) -> Action?
    ) -> ActionBinding<(P0, P1, P2, P3, P4) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.

  • Create a function binding that dispatches an action.

    Declaration

    Swift

    @inlinable
    public func bind<P0, P1, P2, P3, P4, P5>(
      _ getAction: @escaping (P0, P1, P2, P3, P4, P5) -> Action?
    ) -> ActionBinding<(P0, P1, P2, P3, P4, P5) -> Void>

    Parameters

    getAction

    A closure that returns an action to dispatch.

    Return Value

    a function that dispatches the action.