-
Notifications
You must be signed in to change notification settings - Fork 81
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
debounced updateWindow #469
debounced updateWindow #469
Conversation
lib/useKWindowDimensions.js
Outdated
@@ -1,5 +1,6 @@ | |||
import './composition-api'; //Due to @vue/composition-api shortcomings, add plugin prior to use in kolibri, studio and tests | |||
import { onMounted, onUnmounted, ref } from '@vue/composition-api'; | |||
import debounce from 'lodash/debounce'; |
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.
Just FYI, requestAnimationFrame
might be appropriate here because it implements a dynamic throttle. The old responsive window mixin used the frame-throttle
wrapper library for this:
import { throttle } from 'frame-throttle'; |
kolibri-design-system/lib/KResponsiveWindowMixin.js
Lines 74 to 77 in e578ede
const windowResizeHandler = throttle(() => { | |
const metrics = windowMetrics(); | |
windowListeners.forEach(cb => cb(metrics)); | |
}); |
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.
Hello @indirectlylit, Thanks for your review. Just to confirm, do I need to implement it similar to how it is implemented in KResponsiveWindowMixin.js
using throttle
?
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.
Hi @Jaspreet-singh-1032 - that's for you (and @MisRob) to decide. This is a very minor note and should not block the PR.
That said if you're interested, some links:
- https://css-tricks.com/using-requestanimationframe/
- https://css-tricks.com/debouncing-throttling-explained-examples/
Personally, I prefer using this form of throttling for anything related to fluid UI changes because the system can choose an appropriate refresh rate rather than hard-coding a somewhat arbitrary delay period.
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.
Thank you, @indirectlylit, I was previously unaware of this function. I will read about it and If it is a better option then I will definitely use it here.
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.
For most browsers this will use requestAnimationFrame, which will invoke the callback just before the next repaint - which means that it should not be the cause of a reflow by reading the inner width and height of the window (which is a strong part of the motivation for this issue), so I do think this is a good change to use here.
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, @rtibbles, I read some blogs about requestAnimationFrame
and I also think this is a better option to use here.
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 @indirectlylit, that's a good idea
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.
Hi @Jaspreet-singh-1032, with exception build errors that I think are resolvable(Some linting issues at the very least), the changes made, make sense me. (cc @MisRob on the build failures )
I'll push update that will resolve the changelog check after all remaining checks are working and the PR is approved (@akolson this will be done by reviewers eventually for majority of PRs from our contributors, I will follow-up soon) |
@akolson It's not very clear to me if your comment is meant to be approval? Could you please mark it if that's the case? I will then complete the changelog. |
Hi @MisRob! My comment was meant to specifically address the build failure. I see these have been addressed(or to be addressed). I am more confident approving it now. 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.
LGTM!
Okay @akolson, thank you. Changelog is updated. |
Checks should be okay now. Would recommend Kolibri QA pass as part of review. It's up to you how you want to proceed. |
Seems all is done here so merging |
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.
@Jaspreet-singh-1032 One of my colleagues noticed an issue with using setTimeout
after we merged it, so I opened a follow-up #480. You don't need to work on it, of course! It's rather FYI in case you'd find the note interesting. I didn't realize that either.
fixes #461
I also linked this with Kolibri and tested this out, and It seems to be working fine for me.
changelog
Reviewer guidance
Comments