question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: delay option

See original GitHub issue

It would be nice to have a delay option, which will only show the progress bar if .done was not already called within the delay time:

NProgress.configure({delay: 80}) // Only show if not done within 80ms

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:14
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
henrikcommented, May 23, 2020

@msurdi I believe you could simplify that to:

let progressBarTimeout = null;

const startProgressBar = () => {
  clearTimeout(progressBarTimeout);
  progressBarTimeout = setTimeout(nprogress.start, 200);
};

const stopProgressBar = () => {
  clearTimeout(progressBarTimeout);
  nprogress.done();
};

To quote https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout:

Passing an invalid ID to clearTimeout() silently does nothing; no exception is thrown.

And https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout says:

It is guaranteed that a timeout ID will never be reused by a subsequent call to setTimeout() or setInterval() on the same object (a window or a worker). However, different objects use separate pools of IDs.

So it’s fine to run clearTimeout without checking first – it won’t explode on null or old values, and values won’t be reused.

7reactions
msurdicommented, Feb 8, 2019

I’ve extended @fracz idea to avoid patching the library, in case anyone else finds it useful:

let progressBarTimeout = null;

const clearProgressBarTimeout = () => {
  if (progressBarTimeout) {
    clearTimeout(progressBarTimeout);
    progressBarTimeout = null;
  }
};

const startProgressBar = () => {
  clearProgressBarTimeout();
  progressBarTimeout = setTimeout(() => {
    nprogress.start();
  }, 200);
};

const stopProgressBar = () => {
  clearProgressBarTimeout();
  nprogress.done();
};

just use startProgressBar and stopProgressBar instead of nprogress.start/done

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request response email templates - LiveAgent
Answer feature request emails professionally and kindly regardless of the (good or bad) news you're delivering to your customers.
Read more >
179 delay option for multiline commands - YAT
#179 delay option for multiline commands ... This feature request already implemented by keyword \!(Delay), therefore setting this feature ...
Read more >
[feature request] Delay Javascript - WordPress.org
Dear Developer, Giving users the ability to delay the JavaScript of the Instagram plugin until the main page has loaded will significantly improve...
Read more >
10 Tips for Responding Graciously to Customer Feature ...
10 Tips for Responding Graciously to Customer Feature Requests · 1. Be open and honest · 2. Be grateful for their effort ·...
Read more >
Feature Request: Notification Escalation / Delay ... - GitHub
Related to this, I think we need an option to delay notifications in general. What if you want the service marked as down...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found