Skip to content

Reducer

m-housh edited this page Aug 23, 2021 · 3 revisions

Extensions on Reducer

Methods

list(state:action:)

Enhances a reducer with list actions.

public func list<A>(
    state: WritableKeyPath<State, A>,
    action: CasePath<Action, ListAction>
  ) -> Reducer where A: MutableCollection, A: RangeReplaceableCollection 

Parameters

  • state: The list state.
  • action: The list actions.

list(state:action:)

Enhances a reducer with list actions for an optional list.

public func list<A>(
    state: WritableKeyPath<State, A?>,
    action: CasePath<Action, ListAction>
  ) -> Reducer where A: MutableCollection, A: RangeReplaceableCollection 

Parameters

  • state: The list state.
  • action: The list actions.

list(state:action:)

Enhances an IdentifiedArray reducer with list actions.

public func list<Element, Id: Hashable>(
    state: WritableKeyPath<State, IdentifiedArray<Id, Element>>,
    action: CasePath<Action, ListAction>
  ) -> Reducer 

Parameters

  • state: The list state.
  • action: The list actions.

list(state:action:)

Enhances an optional IdentifiedArray reducer with list actions.

public func list<Element, Id: Hashable>(
    state: WritableKeyPath<State, IdentifiedArray<Id, Element>?>,
    action: CasePath<Action, ListAction>
  ) -> Reducer 

Parameters

  • state: The list state.
  • action: The list actions.

editMode(state:action:)

Enhances a reducer with edit mode capabilities.

public func editMode(
    state: WritableKeyPath<State, EditMode>,
    action: CasePath<Action, EditModeAction>
  ) -> Reducer 

Parameters

  • state: The edit mode state.
  • action: The edit mode action.

loadablePicker(state:action:)

Enhances a reducer with loadable picker actions.

public func loadablePicker<Element, Id: Hashable, Failure: Error>(
    state: WritableKeyPath<State, LoadablePickerState<Element, Id, Failure>>,
    action: CasePath<Action, LoadablePickerAction<Element, Id, Failure>>
  ) -> Reducer 

When using this overload, the caller is responsible for implementing / calling the loadable(.load) action with the appropriate request type. However it handles setting the state appropriately on the loadable value.

Parameters

  • state: The loadable picker state.
  • action: The loadable picker action.

loadablePicker(state:action:environment:)

Enhances a reducer with loadable picker actions.

public func loadablePicker<Element, Id: Hashable, Failure: Error>(
    state: WritableKeyPath<State, LoadablePickerState<Element, Id, Failure>>,
    action: CasePath<Action, LoadablePickerAction<Element, Id, Failure>>,
    environment: @escaping (Environment) -> LoadablePickerEnvironment<
      Element, EmptyLoadRequest, Failure
    >
  ) -> Reducer 

Parameters

  • state: The loadable picker state.
  • action: The loadable picker action.
  • environment: The loadable picker environment.

forEach(elementReducer:environment:)

Enhances a reducer with forEach actions for use in a LoadableForEachStore view.

public func forEach<
    Element,
    ElementAction,
    ElementEnvironment,
    Id: Hashable,
    Failure: Error
  >(
    elementReducer: Reducer<Element, ElementAction, ElementEnvironment>,
    environment: @escaping (Environment) -> ElementEnvironment
  ) -> Reducer
  where
    State == LoadableForEachState<Element, Id, Failure>,
    Action == LoadableForEachAction<Element, ElementAction, Id, Failure>

Parameters

  • elementReducer: The reducer for the element.
  • environment: The environment for the element.

forEach(elementReducer:)

Enhances a reducer with forEach actions for use in a LoadableForEachStore view, when the element environment is Void.

public func forEach<
    Element,
    ElementAction,
    Id: Hashable,
    Failure: Error
  >(
    elementReducer: Reducer<Element, ElementAction, Void>
  ) -> Reducer
  where
    State == LoadableForEachState<Element, Id, Failure>,
    Action == LoadableForEachAction<Element, ElementAction, Id, Failure>

Parameters

  • elementReducer: The reducer for the element.

loadableForEachStore(state:action:)

Enhances a reducer with minimal functionality for use in a LoadableForEachStore view.

public func loadableForEachStore<
    Element,
    ElementAction,
    Id: Hashable,
    Failure: Error
  >(
    state: WritableKeyPath<State, LoadableForEachState<Element, Id, Failure>>,
    action: CasePath<Action, LoadableForEachAction<Element, ElementAction, Id, Failure>>
  ) -> Reducer 

When using this overload, the caller must still implement the forEach and loadable(.load) actions appropriately. It will however provide the appropriate state changes on the loadable.

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.

loadableForEachStore(id:state:action:environment:)

Enhances a reducer with all functionality, except the forEach actions for use in a LoadableForEachStore view.

public func loadableForEachStore<
    Element,
    ElementAction,
    Id: Hashable,
    Failure: Error
  >(
    id: KeyPath<Element, Id>,
    state: WritableKeyPath<State, LoadableForEachState<Element, Id, Failure>>,
    action: CasePath<Action, LoadableForEachAction<Element, ElementAction, Id, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironment<
      Element, Id, EmptyLoadRequest, Failure
    >
  ) -> Reducer 

When using this overload, the caller must still implement the forEach actions.

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.

loadableForEachStore(id:state:action:environment:forEach:elementEnvironment:)

Enhances a reducer with all functionality for use in a LoadableForEachStore view.

public func loadableForEachStore<
    Element,
    ElementAction,
    ElementEnvironment,
    Id: Hashable,
    Failure: Error
  >(
    id: KeyPath<Element, Id>,
    state: WritableKeyPath<State, LoadableForEachState<Element, Id, Failure>>,
    action: CasePath<Action, LoadableForEachAction<Element, ElementAction, Id, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironment<
      Element, Id, EmptyLoadRequest, Failure
    >,
    forEach elementReducer: Reducer<Element, ElementAction, ElementEnvironment>,
    elementEnvironment: @escaping (Environment) -> ElementEnvironment
  ) -> Reducer 

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.
  • elementReducer: The reducer for an individual element.
  • elementEnvironment: The environment for an individual element.

loadableForEachStore(id:state:action:environment:forEach:)

Enhances a reducer with all functionality for use in a LoadableForEachStore view, when the element environment is Void.

public func loadableForEachStore<
    Element,
    ElementAction,
    Id: Hashable,
    Failure: Error
  >(
    id: KeyPath<Element, Id>,
    state: WritableKeyPath<State, LoadableForEachState<Element, Id, Failure>>,
    action: CasePath<Action, LoadableForEachAction<Element, ElementAction, Id, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironment<
      Element, Id, EmptyLoadRequest, Failure
    >,
    forEach elementReducer: Reducer<Element, ElementAction, Void>
  ) -> Reducer 

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.
  • elementReducer: The reducer for an individual element.

loadableForEachStore(state:action:environment:forEach:elementEnvironment:)

Enhances a reducer with all functionality for use in a LoadableForEachStore view, when the element is Identifiable.

public func loadableForEachStore<
    Element: Identifiable,
    ElementAction,
    ElementEnvironment,
    Failure: Error
  >(
    state: WritableKeyPath<State, LoadableForEachStateFor<Element, Failure>>,
    action: CasePath<Action, LoadableForEachStoreActionFor<Element, ElementAction, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironmentFor<Element, Failure>,
    forEach elementReducer: Reducer<Element, ElementAction, ElementEnvironment>,
    elementEnvironment: @escaping (Environment) -> ElementEnvironment
  ) -> Reducer 

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.
  • elementReducer: The reducer for an individual element.
  • elementEnvironment: The environment for an individual element.

loadableForEachStore(state:action:environment:forEach:)

Enhances a reducer with all functionality for use in a LoadableForEachStore view, when the element is Identifiable and the element environment is Void.

public func loadableForEachStore<
    Element: Identifiable,
    ElementAction,
    Failure: Error
  >(
    state: WritableKeyPath<State, LoadableForEachStateFor<Element, Failure>>,
    action: CasePath<Action, LoadableForEachStoreActionFor<Element, ElementAction, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironmentFor<Element, Failure>,
    forEach elementReducer: Reducer<Element, ElementAction, Void>
  ) -> Reducer 

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.
  • elementReducer: The reducer for an individual element.

loadableForEachStore(state:action:environment:)

Enhances a reducer with all functionality, except the forEach actions for use in a LoadableForEachStore view, when the element is Identifiable.

public func loadableForEachStore<
    Element: Identifiable,
    ElementAction,
    Failure: Error
  >(
    state: WritableKeyPath<State, LoadableForEachStateFor<Element, Failure>>,
    action: CasePath<Action, LoadableForEachStoreActionFor<Element, ElementAction, Failure>>,
    environment: @escaping (Environment) -> LoadableForEachEnvironmentFor<Element, Failure>
  ) -> Reducer 

When using this overload, the caller must still implement the forEach actions.

Parameters

  • state: The loadable for each state.
  • action: The loadable for each action.
  • environment: The loadable for each environment.

loadable(state:action:)

Enhances a reducer with loadable actions.

public func loadable<Value, Failure>(
    state: WritableKeyPath<State, Loadable<Value, Failure>>,
    action: CasePath<Action, LoadableAction<Value, Failure>>
  ) -> Reducer 

When using this overload the caller still needs to implement / override the load, however it handles setting the state appropriately on the loadable.

Parameters

  • state: The key path to a loadable item.
  • action: The case path to the loadable actions.

loadable(state:action:environment:)

Enhances a reducer with all the loadable actions when the environment's LoadRequest type is equal to EmptyLoadRequest.

public func loadable<E>(
    state: WritableKeyPath<State, Loadable<E.LoadedValue, E.Failure>>,
    action: CasePath<Action, LoadableAction<E.LoadedValue, E.Failure>>,
    environment: @escaping (Environment) -> E
  ) -> Reducer
  where
    E: LoadableEnvironmentRepresentable,
    E.LoadRequest == EmptyLoadRequest

Parameters

  • state: The key path to a loadable item.
  • action: The case path to the loadable actions.
  • environment: The loadable environment.

loadableList(state:action:)

Enhances a reducer with loadable list actions.

public func loadableList<Element, Failure>(
    state: WritableKeyPath<State, LoadableListState<Element, Failure>>,
    action: CasePath<Action, LoadableListAction<Element, Failure>>
  ) -> Reducer 

When using this overload the caller still needs to implement / override the loadable(.load), however it handles setting the state appropriately on the loadable.

Parameters

  • state: The loadable list state.
  • action: The loadable list actions.

loadableList(state:action:environment:)

Enhances a reducer with loadable list actions.

public func loadableList<Element, Failure>(
    state: WritableKeyPath<State, LoadableListStateFor<Element, Failure>>,
    action: CasePath<Action, LoadableListActionFor<Element, Failure>>,
    environment: @escaping (Environment) -> LoadableListEnvironmentFor<Element, Failure>
  ) -> Reducer where Failure: Equatable, Failure: Error 

Parameters

  • state: The loadable list state.
  • action: The loadable list actions.
  • environment: The loadable list environment.
Clone this wiki locally