ajoslin/angular-promise-tracker

Feature Request: Delay option

nathasm opened this issue ยท 21 comments

It would be nice to have a way to tell the tracker to not be active until some time in the future. This would prevent the UI tracker element from displaying for actions that happen quickly.

When you create a promiseTracker, you can pass in an option minDuration or maxDuration - this kind of does what you want. If a request is only active for 100ms and you have a minDuration of 250ms, it will stay active for 250ms.

I saw the documentation for min/max duration. I was looking for a way to delay the promiseTracker from activating for some duration. e.g. a user makes a request, if the request is not satisfied in 250ms, then trigger the tracker. I was looking to trying to implement it myself but I just haven't had time yet.

I am using the promiseTracker to display a loading spinner to let the user know that their request is being processed. The issue I want to avoid is the spinner showing up for requests that take less than X milliseconds.

OK. That sounds like a good option to have. What would you name the option?

If you could open a PR that would be great. Do you have any questions about how to implement it? I know in my head I think.

@nathasm @ajoslin I also like that request. Regarding naming - how about minDelayDuration ?

Or perhaps requiredPromiseDuration - so it has different language than minDuration.

@ajoslin sounds also good, but is much more to type :P

@ajoslin you decide, or maybe we can find more proposals.

Ok, how about minPromiseDuration?

On Nov 1, 2013, at 4:29 AM, Pascal Precht notifications@github.com wrote:

@ajoslin you decide, or maybe we can find more proposals.

โ€”
Reply to this email directly or view it on GitHub.

Hm... to abstract it a bit more away, what about minAsyncDuration ? Or is that too far away?

Or.. waitToActivate or activateDelay

On Nov 1, 2013, at 5:32 PM, Pascal Precht notifications@github.com wrote:

Hm... to abstract it a bit more away, what about minAsyncDuration ? Or is that too far away?

โ€”
Reply to this email directly or view it on GitHub.

๐Ÿ‘

Would also like to see that feature! activateDelay sounds good to me (-;

๐Ÿ‘ I neeeeeed this too ๐Ÿ˜‹

Added in b63b39d

//500ms activationDelay, then after the delay should always be active for at least 1000ms
var tracky = promiseTracker('tracky', { 
  activationDelay: 500
  minDuration: 1000
});

Could you guys put this in your projects and lemme know if it works for you: https://gist.github.com/ajoslin/10d57275fda38128d9e3/raw/081ae3887ab36f3de6a1e54f3b5e7616f90ac3f0/promiseTracker.js

I'm currently writing docs for it.

@ajoslin

activationDelay: 500

is not working. E.g. I set activationDelay: 10000, however the loader will show up.

minDuration: 1000

works.

This test works for me: http://plnkr.co/edit/Ee6PRLxvH92hjRDBrLKw?p=preview

Can I see an example?

When I bootstrap my app:

$rootScope.tracker = promiseTracker('globalTracker', {
    activationDelay: 1000,
    minDuration: 500
});

In service method:

 list: function() {
     var url = BASE + 'city';
     var promise = $http.get(url, {
           tracker: 'globalTracker'
     }).then(function(response) {
           return response.data;
     });
     return promise;
 }

@ajoslin from web console I see that loading takes just 50 millisec. However the loader is displayed immediately when loading starts. Am I using it wrong?

I have the suspicion that perhaps your list method is being called before you first instantiate the promiseTracker. Could you add a console.log in each of those spots?

If that is the case, I should do what I always should've done: made promiseTrackers be registered seperately from getting them, maybe only during config phase. But we will see.

FYI: I just tried the latest, and appears to do exactly what I needed! Thanks!

Added in v1.5.1 :-)

Also, we finally have proper documentation in the README. Open a PR if you see some issues with it.

@ajoslin ๐Ÿ‘ thank you, I switched from master to v1.5.1 and magically it works...