ActionPlan

public struct ActionPlan<State> : Action where State : Decodable, State : Encodable

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))
   }
```.
  • The body of a publishable action plan.

    Declaration

    Swift

    public typealias Body = (StoreProxy<State>) -> AnyPublisher<Action, Never>?

    Parameters

    StoreProxy

    Dispatch actions or retreive the current state from the store.

    Return Value

    A publisher that can send actions to the store.

  • Create a new action plan that returns an optional publisher.

    Declaration

    Swift

    public init<P>(_ body: @escaping (StoreProxy<State>) -> P?) where P: Publisher, P.Output == Action, P.Failure == Never

    Parameters

    body

    The body of the action plan.

  • Create a new action plan.

    Declaration

    Swift

    public init(_ body: @escaping (StoreProxy<State>) -> Void)

    Parameters

    body

    The body of the action plan.

  • Manually run the action plan.

    this can be useful to run an action plan inside a containing action plan.

    Declaration

    Swift

    public func run(_ store: StoreProxy<State>) -> AnyPublisher<Action, Never>?

    Parameters

    store

    Dispatch actions or retreive the current state from the store.

    Return Value

    A publisher that can send actions to the store.