-
Notifications
You must be signed in to change notification settings - Fork 832
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
[Calendar] Remove promise based loading in favor of loading
prop
#1829
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40bc077
Remove `onMonthChange` promise-based api in favor of `loading` prop
dmtrKovalenko e106849
Update server request example for new API
dmtrKovalenko 04fe2fa
Implement fake api for server request example
dmtrKovalenko ae1a1c0
Update tests
dmtrKovalenko 7e3286f
Make CalendarSkeleton component and use it in the examples for loadin…
dmtrKovalenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ coverage | |
# editors | ||
.vs | ||
.DS_Store | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getDaysInMonth, isValid } from 'date-fns'; | ||
import { NowRequest, NowResponse } from '@now/node'; | ||
|
||
function getRandomNumber(min: number, max: number) { | ||
return Math.round(Math.random() * (max - min) + min); | ||
} | ||
|
||
export default function(req: NowRequest, res: NowResponse) { | ||
const { month } = req.query; | ||
if (!month || typeof month !== 'string') { | ||
res.status(400); | ||
return res.json({ | ||
reason: 'month query param is required', | ||
}); | ||
} | ||
|
||
const date = new Date(month); | ||
if (!isValid(date)) { | ||
res.status(422); | ||
return res.json({ | ||
reason: 'cannot parsable month value', | ||
}); | ||
} | ||
|
||
setTimeout(() => { | ||
const daysInMonth = getDaysInMonth(date); | ||
const daysToHighlight = [1, 2, 3].map(_ => getRandomNumber(1, daysInMonth)); | ||
|
||
res.json({ daysToHighlight }); | ||
}, 500); // fake some long work | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if the component unmounts before the request resolves? I believe the set state call will warn/throw. The solution proposed in could be applied here too mui/mui-x#5 (comment)
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.
We are saving abort controller. So needs to make an effect that will abort request on unmount. thanks
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's one way to solve this. I have no idea what's the best approach. I guess it's good enough, no need to look further 👍
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.
Interesting, but I think that this solution has one giant pitfall – it doesn't abort the request.
Probably if we want to support IE we must not use fetch and promises at all.
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.
Can requests be aborted? I mean, does it change something at the network layer?
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.
Actually request/response model cannot be aborted, but browsers can prevent some calculations on the responses if they are aborted (like processing low-level body and CORS)
Here network log when fast switching between months with request aborts:
Without:
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.
Nice :)