ActionType

public protocol ActionType

This protocol is used when you want to make modifications to the store’s state. All changes to the store go through this type.

Sample Action:

struct UpdateIdAction: ActionType {
    let id: Int

    func reduce(state: AppState) -> AppState {
        state.id.value = id
        return state
    }
}

store.dispatch(UpdateIdAction(id: 1))
  • This method is called when this action is dispatched. Its purpose is to make modifications to the state and return a new version of it.

    Note

    This is the only place that changes to the state are permitted.

    Declaration

    Swift

    func reduce(state: StateValueType) -> StateValueType

    Parameters

    state

    The current state of the store.

    Return Value

    The new state.

  • The type of the app’s state.

    Note

    This is inferred from the reduce method implementation.

    Declaration

    Swift

    typealias StateValueType