-
Notifications
You must be signed in to change notification settings - Fork 245
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
feat: allow $loading indicator throttling #247
base: dev
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #247 +/- ##
===================================
Coverage 100% 100%
===================================
Files 1 1
Lines 27 27
Branches 12 12
===================================
Hits 27 27 Continue to review full report at Codecov.
|
5b505c5
to
777b63e
Compare
author Simon Tretter <[email protected]> 1557759137 +0200 committer simon <[email protected]> 1557760081 +0200 allows $loading indicator throttling Problem: Right now the loading indicator is shown even for very short request. Which results in a "flashing" that looks more like a bug than a feature ;) Reason & Solution: when using .set on $loading it shows immediately the loading indicator. (see nuxt-loading.vue) The indicator itself has a throttle property though (which is only checked on .start()). As long as we only have one request, there is no additional benefit of using .set directly, therefore we can rely on the throttle parameter by using start() instead. Different approach: Another approach would be implementing our own "throttle" method which sets a timer on "onRequest" when it's not set) or currentRequests === 0), and removes the timer again onResponse when currentRequests <= 0. But then we need another config option for the throttling param, or can we access the one from nuxt.config's loading property somehow? Regards Simon
Codecov Report
@@ Coverage Diff @@
## dev #247 +/- ##
===================================
Coverage 100% 100%
===================================
Files 1 1
Lines 27 27
Branches 12 12
===================================
Hits 27 27 Continue to review full report at Codecov.
|
I've seen there is also another PR hanging arround regarding this issue. I've solved this for me now by:
2.) using my own axios-enrichment plugin, which I have in place anyway where I added follwoing code:
dont forget to add this in nuxt.config as plugin: hope it's helpful. regards |
@@ -139,8 +142,10 @@ const setupProgress = (axios, ctx) => { | |||
if (!currentRequests) { | |||
return | |||
} | |||
const progress = ((e.loaded * 100) / (e.total * currentRequests)) | |||
$loading().set(Math.min(100, progress)) | |||
if (currentRequests > 1) { |
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.
With this condition, we don't precisely show progress with single requests (but random jumps). Is it desired?
Thanks, @simllll for this PR and sorry about late review/answer. I just left a minor comment about this change. I think what you have proposed in your second comment is more reasonable (only call to |
(ping @simllll) |
hi @manniL,
The problem with that is, as soon as we set the progress the bar appears, therefore this would need some special handling which I'm unsure if this is really necessary. Regards |
I would really think there would be a larger layer of abstraction between the loading component and it's integration with plugins. I would assume there would be a way for plugins to simply say, "hey nuxt, I'm loading 3 things.... now I'm loading 2 things.... now 1 etc..." and nuxt's loading component would figure out how to render that abstraction over time. I really don't think plugins should be talking directly to the loading component. |
any news? |
Problem:
Right now the loading indicator is shown even for very short request. Which results in a "flashing" that looks more like a bug than a feature ;)
Reason & Solution:
when using .set on $loading it shows immediately the loading indicator. (see nuxt-loading.vue) The indicator itself has a throttle property though (which is only checked on .start()). As long as we only have one request, there is no additional benefit of using .set directly, therefore we can rely on the throttle parameter by using start() instead.
Different approach:
Another approach would be implementing our own "throttle" method which sets a timer on "onRequest" when it's not set) or currentRequests === 0), and removes the timer again onResponse when currentRequests <= 0.
But then we need another config option for the throttling param, or can we access the one from nuxt.config's loading property somehow?
Regards
Simon