-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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 support for multiple callbacks in ReactScheduler #12682
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d376543
Add support for multiple callbacks in ReactScheduler
flarnie fea65d6
Move back to using pooling with frameDeadlineObject
flarnie 5f450b8
clearTimeoutTimeAndScheduledCallback -> resetScheduledCallback
flarnie 079bb73
Assert callback order in scheduler test for multiple callback support
flarnie df6624b
Fix case of scheduled callbacks which schedule other callbacks
flarnie c1278be
comment wording nit
flarnie 8283c95
remove destructuring
flarnie eb0110f
Handle errors thrown by callbacks in `schedule`
flarnie 0c47fe2
Add initial test for cIC
flarnie e96d0e3
Add stronger types and refactoring in `ReactScheduler`
flarnie 26b82c8
Return an id when scheduling callback; use it for cancelling callback
flarnie 64b57b1
Use 'toEqual' instead of 'toBe' in schedule tests; more precise/concise
flarnie 8703f21
Use Map instead of object for registeredCallbackIds
flarnie 5ba093b
Restructure 'schedule' rIC code for clarity
flarnie 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
Assert callback order in scheduler test for multiple callback support
- Loading branch information
commit 079bb73eb680aaf82ff5132d84ef426d2599597a
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 |
---|---|---|
|
@@ -54,19 +54,21 @@ describe('ReactScheduler', () => { | |
|
||
it('rIC with multiple callbacks flushes previous cb when new one is passed', () => { | ||
const {rIC} = ReactScheduler; | ||
const callbackA = jest.fn(); | ||
const callbackB = jest.fn(); | ||
const callbackLog = []; | ||
const callbackA = jest.fn(() => callbackLog.push('A')); | ||
const callbackB = jest.fn(() => callbackLog.push('B')); | ||
rIC(callbackA); | ||
// initially waits to call the callback | ||
expect(callbackA.mock.calls.length).toBe(0); | ||
expect(callbackLog.length).toBe(0); | ||
// when second callback is passed, flushes first one | ||
rIC(callbackB); | ||
expect(callbackA.mock.calls.length).toBe(1); | ||
expect(callbackB.mock.calls.length).toBe(0); | ||
expect(callbackLog.length).toBe(1); | ||
expect(callbackLog[0]).toBe('A'); | ||
// after a delay, calls the latest callback passed | ||
jest.runAllTimers(); | ||
expect(callbackA.mock.calls.length).toBe(1); | ||
expect(callbackB.mock.calls.length).toBe(1); | ||
expect(callbackLog.length).toBe(2); | ||
expect(callbackLog[0]).toBe('A'); | ||
expect(callbackLog[1]).toBe('B'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you assert on the entire array, like this... expect(callbackLog).toEqual(['A', 'B']); then it guarantees that the callbacks are only called once. It's also easier to read, IMO. I have a harder time trying to follow what's happening when I have to recreate the list of operations in my head :D |
||
// callbackA should not have timed out and should include a timeRemaining method | ||
expect(callbackA.mock.calls[0][0].didTimeout).toBe(false); | ||
expect(typeof callbackA.mock.calls[0][0].timeRemaining()).toBe('number'); | ||
|
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.
This test should assert that the callbacks were called in the correct order