-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add async mutation support #134
Conversation
cacheSet(key, data) | ||
let data, error | ||
|
||
if (_data && typeof _data.then === '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.
You can await a non-promise too. Not sure if there is a performance issue though
if (_data && typeof _data.then === 'function') { | |
const data = await _data; |
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.
It will defer the execution order (await non-promise values), similar to process.nextTick
. But the major reason is that for promises (which should be mutation requests), we don't have to revalidate again after the request in most cases.
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.
Great feature idea! The actual code looks good to me.
Co-Authored-By: Paco <[email protected]>
With this change, the
data
parameter ofmutate
can be a promise, which returns the data or throws an error:It can simplify scenarios like
to:
Related: #93.