Skip to content

Commit

Permalink
Fixed Queue#push
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Kurkin committed Mar 16, 2016
1 parent 70ef731 commit a36fb8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 1 addition & 3 deletions Response.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,7 @@ Queue.prototype.stop = function () {
* @returns {Queue}
*/
Queue.prototype.push = function (item, name) {
var keyIndex = this.items.length + this.stateData.length + Number(this.isStarted);

this.keys[keyIndex] = arguments.length > 1 || item == null ? name : item.name;
this.keys.push(arguments.length > 1 || item == null ? name : item.name);
this.items.push(item);

return this;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Response",
"author": "Vladislav Kurkin <[email protected]> (https://github.com/B-Vladi)",
"version": "0.1.3",
"version": "0.1.4",
"main": "Response.js",
"license": "MIT",
"repository": {
Expand Down
26 changes: 24 additions & 2 deletions spec/Queue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,31 @@ describe('Queue:', function () {
expect(queue.items).toEqual([i0, i1, i2, i2, i3, i3]);
});

it('dynamic push in items', function () {
it('order of the keys by dynamic addition', function () {
var q = new Queue();

queue = new Queue()
.push({
.push(1, 'a')
.push(function b () {
expect(this.keys).toEqual(['a', 'b', 'c']);

this.push(q, 'd');

expect(this.keys).toEqual(['a', 'b', 'c', 'd']);
expect(this.keys.length).toBe(4);

return q;
})
.push(3, 'c')
.start();

q.resolve();

expect(queue.keys).toEqual(['a', 'b', 'c', 'd']);
});

it('dynamic push in items', function () {
queue = new Queue({
name: 'key0'
})
.push(function key1 () {
Expand Down

0 comments on commit a36fb8c

Please sign in to comment.