angular-evaporate icon indicating copy to clipboard operation
angular-evaporate copied to clipboard

An option to $dequeue() automatically when completed

Open ryaz opened this issue 9 years ago • 9 comments

Hey Denis, is there any way to call some function on evaporate callback? Thanks!

ryaz avatar Oct 06 '16 19:10 ryaz

Hi! Could you please clarify a little more? I don't really understand what do you want to achieve.

uqee avatar Oct 07 '16 18:10 uqee

Thanks for quick reply! I figured it out in my own way, but I think it should be something simplier and more straightforward:

      $scope.ae.$add({
        file: file,
        started: function () {
          console.log('started');
        },
        complete: function () {
          var now = Date.now();
          console.log('complete................yay!');
          this.$stopped = now;
          uploadSuccessCallback(this.$url);
          this.$dequeue();
        },
        error: function (msg) {
          var now = Date.now();
          this.$errorMsg = msg;
          this.$stopped = now;
          console.log('Upload #%f failed, msg = %s', this.$id, msg);
          uploadFailedCallback(msg);
        }
      });

because I have to manually set $stopped and $dequeue

ryaz avatar Oct 07 '16 19:10 ryaz

  1. The necessity of automatic $dequeue() when completed is debatable for me. Probably somebody would want the opposite if we changed this behaviour.
  2. But I'm worried about the $stopped and $errorMsg values. Are you sure they were really undefined before you manually set them? If so, it's definitely a bug, but a strange one, because they're being set right before the custom callback is going to be launched. Could you provide a complete fiddle may be?

uqee avatar Oct 07 '16 19:10 uqee

  1. So I think it will be cool to have it in settings. In your approach you have all uploads in one place, thats why it doesnt make any sense for you do dequeue upload after its finished. But imagine situation when you have tiles on UI showing progresses on each tile. And you want to hide progress bar and do some UI stuff when upload is finished. In that situation it would be cool and makes sense to dequeue upload.
  2. I'll double check and do fiddle later today or on monday if it doesn't work.

ryaz avatar Oct 07 '16 19:10 ryaz

  1. Ok, now I got it. You're talking about some new flag, like $rinserepeat, for a directive, right? Probably a good idea, worth to be considered at least. I'll tag this thread accordingly and implement it as soon as I have time (unfortunately, not very soon). If you need this right now, then a PR is a good idea, but I guess you don't)
  2. Good.

uqee avatar Oct 07 '16 20:10 uqee

  1. Yeah, I meant it. It would be cool to run some callback on $dequeue.
  2. You were right $stopped is set on complete and on error, my bad.

I found another issue. I got error 'Error completing upload'. And right after error, complete callback was called. Is that by design? Maybe it make sense to have completed and finished? Because right now I have completed upload but with error 'Error completing upload'...

ryaz avatar Oct 07 '16 21:10 ryaz

Well, the callbacks are fired by Evaporate itself, whereas AngularEvaporate just wraps them to implicitly save timestamps, messages and some other similar stuff. So in case of their odd behaviour or to request a new one, it's conceptually better to report an issue there, then implement a custom dependant fix here.

uqee avatar Oct 07 '16 23:10 uqee

Btw, why do you need a callback on dequeue? It's a synchronous operation, so basically you can do whatever you need right after dequeuing. And when it dequeues automatically on complete, you still have a complete callback.

uqee avatar Oct 07 '16 23:10 uqee

Yeah, I do something like that. Wrapping dequeue in controller function. So maybe this way is better, thanks. Was just curious about to have upload.$dequeue calling some stuff under the hood.

ryaz avatar Oct 09 '16 18:10 ryaz