You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just looking at the docs, I wondered did you have any opinion on the best way to handle async calls, for example triggering a network request as a side effect of an action?
I'm thinking for example if I dispatch an action such as FetchBookFromAPI(id: "some-book-id") I would like that action to trigger a network request, by passing id as an argument to my networking client. On success of that request I can dispatch another action with the response as a payload and populate my store.
Looking at the ActionLogger I see how I can intercept requests, but I am struggling to see how, rather than creating a middleware for each async action, how I can trigger the request?
public func ActionLogger<S>() -> Middleware<S> {
return { dispatch, getState in
return { next in
return { action in
print("Action: ", action)
return next(action)
}
}
}
}
Any thought on that would be appreciated so much :)
The text was updated successfully, but these errors were encountered:
Just looking at the docs, I wondered did you have any opinion on the best way to handle async calls, for example triggering a network request as a side effect of an action?
I'm thinking for example if I dispatch an action such as
FetchBookFromAPI(id: "some-book-id")
I would like that action to trigger a network request, by passingid
as an argument to my networking client. On success of that request I can dispatch another action with the response as a payload and populate my store.Looking at the
ActionLogger
I see how I can intercept requests, but I am struggling to see how, rather than creating a middleware for each async action, how I can trigger the request?Any thought on that would be appreciated so much :)
The text was updated successfully, but these errors were encountered: