Skip to content

Commit

Permalink
feat(queue): switch to array queue method
Browse files Browse the repository at this point in the history
  • Loading branch information
codysherman committed May 20, 2016
1 parent 26f7753 commit c95eea8
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions letsgo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
/*!
* letsGo
* http://useletsGo.com/
*
* By: Cody Sherman <[email protected]> (codysherman.com)
*/

'use strict';

var letsGoRunning = false;
var letsGoTicketsOut = 0;
var letsGoTicketsDone = 0;

var letsGoQueue = [];

var letsGo = function(target, command, attribute, queue) {
var queueMatters = false;

var nextInQueue = function(lastOne) {
if (queueMatters && lastOne) {
letsGoQueue.shift();
if (letsGoQueue.length > 0) {
router(letsGoQueue[0][0], letsGoQueue[0][1], letsGoQueue[0][3]);
} else {
letsGoRunning = false;
}
}
};

var checkIfAttribute = function(element, attribute, attributeIsClass) {
if (!attribute || attributeIsClass) {
attribute = (attribute) ? attribute : 'letsGo-hide';
Expand Down Expand Up @@ -45,10 +61,7 @@ var letsGo = function(target, command, attribute, queue) {
element.classList.remove(attribute + '-' + command);
element.classList.remove(attribute + '-' + command + '-active');
element.classList.remove('letsGo-animate');
if (queueMatters && lastOne) {
letsGoTicketsDone++;
letsGoRunning = false;
}
nextInQueue(lastOne);
};

element.classList.add('letsGo-animate');
Expand Down Expand Up @@ -89,10 +102,7 @@ var letsGo = function(target, command, attribute, queue) {
element.removeAttribute(attribute);
}
}
if (queueMatters && lastOne) {
letsGoTicketsDone++;
letsGoRunning = false;
}
nextInQueue(lastOne);
}
};

Expand Down Expand Up @@ -253,18 +263,26 @@ var letsGo = function(target, command, attribute, queue) {
}
};

var queueControl = function(target, command, attribute, claimedTicket) {
if (!claimedTicket) {
claimedTicket = letsGoTicketsOut++;
}
if (letsGoRunning && letsGoTicketsDone !== claimedTicket) {
setTimeout(function () {
queueControl(target, command, attribute, claimedTicket);
}, 0);
} else {
letsGoRunning = true;
router(target, command, attribute);
}
var queueControl = function(target, command, attribute) {
// if (!claimedTicket) {
// claimedTicket = ++letsGoTicketsOut;
// }
// if (letsGoRunning && letsGoTicketsDone !== claimedTicket) {
// setTimeout(function () {
// queueControl(target, command, attribute, claimedTicket);
// }, 0);
// } else {
// console.log('Doing', claimedTicket, target);
// letsGoRunning = true;
// router(target, command, attribute);
// }
setTimeout(function () {
letsGoQueue.push([target, command, attribute]);
if (!letsGoRunning) {
letsGoRunning = true;
router(letsGoQueue[0][0], letsGoQueue[0][1], letsGoQueue[0][3]);
}
}, 0);
};


Expand Down

0 comments on commit c95eea8

Please sign in to comment.