Skip to main content
A protocol that describes how to evolve the current state of an application to the next state, given an action, and describes what effects should be executed later by the store, if any.

Protocol Definition

Associated Types

associatedtype
A type that holds the current state of the reducer.
associatedtype
A type that holds all possible actions that cause the State of the reducer to change and/or kick off a side Effect that can communicate with the outside world.
associatedtype
A type representing the body of this reducer. When you create a custom reducer by implementing the body property, Swift infers this type from the value returned. If you create a custom reducer by implementing reduce(into:action:), Swift infers this type to be Never.

Properties

some ReducerOf<Self>
The content and behavior of a reducer that is composed from other reducers. In the body of a reducer one can compose many reducers together, which will be run in order, from top to bottom.
Do not invoke this property directly. It is called by the Store.

Methods

(inout State, Action) -> Effect<Action>
Deprecated: Don’t invoke a reducer directly. Reducers are processed by the store. If you need to run a reducer on some child state given some child action, use a ‘send’ effect instead.

Usage

Define a reducer by conforming to the Reducer protocol and implementing the body property:

Composing Reducers

Reducers can be composed together in the body using reducer operations:

Type Aliases

typealias
A convenience for constraining a Reducer conformance:
This allows you to specify the body of a Reducer conformance like:
Instead of the more verbose: