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.
Ah yeah, I see. Never really changed timeout on the fly
I would probably consider having this check in a separate function and reused in sCU.
callback
is also needed.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.
Oh you're right, what am I thinking. We could accomplish that by removing the top-level
if
statement altogether, because sCU ensures that one of those props will have updated ifcomponentDidUpdate
gets called.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 this PR is fine as it is because the
callback
prop is wrapped by the class property that calls it and sets the next timeout, so even if thecallback
changes, when the timer fires it will call the latestcallback
.I don't understand why not just use an actual
setInterval
though.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.
Because if task takes more time then interval tasks will start to overlap and queue. SetTimeout will not have this issue and will execute only when it actually capable
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.
The problem with callback is if you change callback on the fly, then it will not restart the timer. Same issue as for timeout.
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.
@nkbt I would say if the task takes that long it's probably a major problem with the user's code.
I think restarting the timer when the
callback
changes is probably a bad idea because if the user uses an inline function for thecallback
the timer will reset every time it gets a new inline function instance.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.
Yeah =( this is why we never use inline functions, or have custom sCU that totally ignore any functions and only care about values
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.
Right. In any case I don't think any further changes are necessary here