Actions

  • A dispatchable action that provides information to a reducer to mutate the state of the application.

    Typically this is done with enum types, however, it could be added to protocols or structs if a more complex solution is needed. Structs are also a could choice if actions need to be codable.

      enum TodoList : Action {
        case setItems(items: [TodoItem])
        case addItem(withText: String)
        case removeItems(at: IndexSet)
        case moveItems(at: IndexSet, to: Int)
      }
    
      // You can also create new protocols that represent an entire feature's actions.
      // This can allows views to update off of a granular action or any actions
      // of a given feature.
      protocol FeatureLevelAction : Action {}
    
      enum SubfeatureAction: FeatureLevelAction {
        ...
      }
    

    Declaration

    Swift

    public protocol Action
  • A noop action used by reducers that may not have their own actions.

    Declaration

    Swift

    public struct EmptyAction : Action
  • Encapsulates multiple actions into a packaged up action plan

       enum UserAction {
    
         static func loadUser(byId id: String) -> ActionPlan<AppState> {
           ActionPlan<AppState> { store in
             guard !store.state?.users.hasValue(id) else { return nil }
             store.send(UserAction.setLoading(true))
             return UserService.getUser(id)
               .first()
               .flatMap { user in
                   Publishers.Sequence<[Action], Never>(sequence: [
                     UserAction.setUser(user)
                     UserAction.setLoading(false)
                   ])
                 }
               }
           }
         }
    
       }
    
       // Somewhere inside a view:
    
       func loadUser() {
         dispatch(UserAction.loadUser(byId: self.id))
       }
    ```.
    
    See more

    Declaration

    Swift

    public struct ActionPlan<State> : Action where State : Decodable, State : Encodable
  • An object that dispatches actions to a store.

    Once an action is sent, the sender shouldn’t expect anything to occur. Instead, it should rely solely on changes to the state of the application to respond.

    See more

    Declaration

    Swift

    public protocol ActionDispatcher
  • A closure that dispatches an action.

    Declaration

    Swift

    public typealias SendAction = (Action) -> Void

    Parameters

    action

    Dispatches the given state synchronously.

  • A closure that can return a new action from a previous one. If no action is returned, the original action is not sent.

    Declaration

    Swift

    public typealias ActionModifier = (Action) -> Action?