-
Notifications
You must be signed in to change notification settings - Fork 194
Handle sync requests without await #165
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
Handle sync requests without await #165
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together @artemtsushko -- I have a couple concerns below but this looks nice!
next(await actionWith(requestType, [action, getState()])); | ||
if ( | ||
typeof requestType.payload === 'function' || | ||
typeof requestType.meta === 'function' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the other requestType
properties that can be passed as functions? ie, headers
, options
or bailout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
headers
, options
or bailout
aren't properties of requestType
, they are properties of [RSAA]
, thus this change doesn't apply to them.
) { | ||
next(await actionWith(requestType, [action, getState()])); | ||
} else { | ||
next(requestType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible/worth it to add tests that verify this does happen synchronously, as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's neither worth nor possible to test that this happens synchronously. Provided there is no mistake in if
condition, and taking into account there is no await
in else
branch, this should work as expected. I have added 2 tests that cover first branch of this if
statement, and they ensure that meta
or payload
functions are called, that they are called with correct arguments, and that their result is inserted to meta
or payload
property of request FSA. A lot of existing tests cover the second branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your helpful responses @artemtsushko 👍
Addresses #94. The fix is copied from #95, but targets version 2.0.
Also added 2 tests to keep 100% coverage and make sure that cases when request type descriptor's 'meta' or 'payload' properties are functions are still handled properly.