Actions

  • A dispatchable action to update the application state.

      enum TodoList : Action {
        case setItems(items: [TodoItem])
        case addItem(withText: String)
        case removeItems(at: IndexSet)
        case moveItems(at: IndexSet, to: Int)
      }
    
    See more

    Declaration

    Swift

    public protocol Action
  • Encapsulates external business logic outside of a reducer into a special kind of action.

       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
                   [
                     UserAction.setUser(user)
                     UserAction.setLoading(false)
                   ].publisher
                 }
               }
           }
         }
       }
    
       // Inside a view:
    
       func body(props: Props) -> some View {
         UserInfo(user: props.user)
           .onAppear { dispatch(UserAction.loadUser(byId: self.id)) }
       }
    ```.
    
    See more

    Declaration

    Swift

    public struct ActionPlan<State> : RunnableAction
  • 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
  • An action that performs external logic outside of a reducer.

    See more

    Declaration

    Swift

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

    See more

    Declaration

    Swift

    public struct EmptyAction : Action
  • A closure that dispatches an action.

    Declaration

    Swift

    public typealias SendAction = (Action) -> Void

    Parameters

    action

    The action to dispatch.