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>

    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(dispatch getAction: @escaping () -> Action?) -> () -> 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>(dispatch getAction: @escaping (P0) -> Action?) -> (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>(dispatch getAction: @escaping (P0, P1) -> Action?) -> (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>(
      dispatch getAction: @escaping (P0, P1, P2) -> Action?
    ) -> (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>(
      dispatch getAction: @escaping (P0, P1, P2, P3) -> Action?
    ) -> (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>(
      dispatch getAction: @escaping (P0, P1, P2, P3, P4) -> Action?
    ) -> (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>(
      dispatch getAction: @escaping (P0, P1, P2, P3, P4, P5) -> Action?
    ) -> (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.