-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Extend createAsyncAction API to be able to carry over request information to success and failure handlers #73
Comments
Hi @abersnaze, |
This seems like a specific use case, seems strange to add this to this library. |
@Carl-Foster I think the intention here is to add a more generic API to export const add = createStandardAction(ADD).map(
({ title }: { title: string }) => ({
payload: { title, id: cuid(), completed: false } as Todo,
request: 'whatever you want',
})
); To be honest I was thinking about adding something similar initially on I'll come back to this issue again at some point when I solve some other pending issues that are more important ATM. |
@issuehuntfest has funded $20.00 to this issue. See it on IssueHunt |
@IssueHunt has funded $60.00 to this issue.
|
Here the solution to the requested feature with the new export const fooAction = createAsyncAction(
'FOO_INIT',
'FOO_DONE',
'FOO_ERROR'
)<Foo, [Bar, Foo], [Error, Foo]>();
fooAction.request(foo);
fooAction.success(bar, foo);
fooAction.failure(err, foo); Results: |
I have a bunch of epics that have a similar pattern.
The problem that I'm having is that the Error type loses the request value (of type Foo). To properly mutated the state in the reducer I've had to compose the Error and Foo together in the epic. So the async action creator now looks like this.
I was wondering if the request payload can be carried over to the success and failure actions?
InputAction would be the same
{ type: string, payload: I }
OutputAction would be
{ type: string, payload: O, request: I }
ErrorAction would be
{ type: string, payload: E, request: I }
The text was updated successfully, but these errors were encountered: