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.

how to dequeue elements from a custom queue using shim

See original GitHub issue

I’m currently using the shim and I’m not too sure if I’m dequeue a queue correctly.

I have an array of elements in which I loop through calling Velocity(element, propertiesMap, options) on each one. options has a queue property with a value of “itemQueue”. I then dequeue the elements by calling Velocity(elementsArray, propertiesMap, { queue: false }) which runs the animation as expected except that subsequent runs are getting longer and longer to start the animation.

I’m thinking that the queue is not being dequeued properly, but I can’t figure out how to do it with the shim syntax.

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fattenapcommented, Aug 22, 2014

No, not really.

This is the code and maybe you can see what I’m doing wrong or a better way of doing it.

During initialization the UI sends an element, which usually represents a list of items. Every time I receive an element I push it onto my queue called elementQueue to be animated later. Below is the code snippet

if(isTransitioning){
  //push onto my queue
  elementQueue.push(element);
//store the props and options for the animation later on
  itemsInPropMap = propertiesMap;
  ItemsInOpts = options;
// add a custom queue prop and pass it to Velocity
  options = options || {};
  options.queue = "testQ";
  return Velocity(element, propertiesMap, options);
}

Then after the UI has initialized I call my dequeueElements function

var dequeueElements = function(){
//clone elementsQueue and then clear it
    animationQueue = elementQueue.slice(0);
    elementQueue = [];
//dequeue elements
// This does dequeue as far as I can see but it doesn't animate the elements
    animationQueue.forEach(function(ele){
        Velocity.Utilities.dequeue(ele, "testQ");
    });
};

I loop through the elements to dequeue them, which seems to dequeue them properly. They appear but they do not get animated. I’ve tried different approaches with, like passing options.queue = “false”, varying results.

Sorry I’m going to add another variation, which I thought would work, but the items aren’t visible, but they are there.

if(isTransitioning){
  hasElements = true;
  elementQueue.push(element);
  options = options || {};
  options.queue = "testQ";
  itemsInPropMap = propertiesMap;
  ItemsInOpts = options;  
  // Spoof then()
  return then();//
}

then calling

var dequeueElements = function(stop){
  animationQueue = elementQueue.slice(0);
  elementQueue = [];
  ItemsInOpts.queue = "false";
  Velocity(animationQueue, itemsInPropMap, ItemsInOpts).then(function(elements){
      elements.forEach(function(ele){
        Velocity.Utilities.dequeue(ele, "testQ");
      });
      isTransitioning = false;
      animationQueue = [];
      hasElements = false;
      itemsInPropMap = void(0);
      ItemsInOpts = void(0);
      return elements;
  });
};

Oh and itemsInPropMap === “transition.slideRightIn” and ItemsInOpts = { stagger: 175, drag: true }

0reactions
fattenapcommented, Aug 25, 2014

OK. I figured out whats been happening.

I want to say up front that I stopped using the custom queues, which seem to work by the way, because it wasn’t what I needed. But thanks for the CodePen, it helped me understand what custom queues are for and how to use them properly.

Thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implement Stack and Queue using Deque - GeeksforGeeks
Now, deque can be used to implement a stack and queue. ... displays the elements in deque. void display() ... pop to remove...
Read more >
Custom Queue Implementation in Java - DevGlan
In this article, we will create a custom implementation of Queue ... deQueue(): Removes and returns the element at the front of the...
Read more >
Creating a Queue in C | DigitalOcean
dequeue () : Removes the element from the frontal side of the queue; enqueue() : It inserts elements to the end of the...
Read more >
Java Queue - Queue Methods, Queue Implementation ...
#2) Dequeue: The operation to delete an element from the queue is Dequeue (function queueDequeue in the program). First, we check whether the ......
Read more >
Implement Efficient Queues Using Python's collections Module
Creating a Custom Queue Class Using deque · enQueue() will add elements to the queue · deQueue() will remove elements from the queue...
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