Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling async requests as a side effect? #6

Closed
nodediggity opened this issue Dec 5, 2018 · 1 comment
Closed

Handling async requests as a side effect? #6

nodediggity opened this issue Dec 5, 2018 · 1 comment

Comments

@nodediggity
Copy link

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 :)

@svdo
Copy link
Owner

svdo commented Dec 8, 2018

I recommend looking at https://github.com/mikecole20/ReSwiftThunk, I think that might be the thing you're looking for.

@svdo svdo closed this as completed Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants