Actions
-
A dispatchable action to update the application state.
See moreenum TodoList : Action { case setItems(items: [TodoItem]) case addItem(withText: String) case removeItems(at: IndexSet) case moveItems(at: IndexSet, to: Int) }
Declaration
Swift
public protocol Action
-
Encapsulates external business logic outside of a reducer into a special kind of action.
See moreenum 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)) } } ```.
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 moreDeclaration
Swift
public protocol ActionDispatcher
-
A closure that dispatches an action.
Declaration
Swift
public typealias SendAction = (Action) -> Void
Parameters
action
The action to dispatch.