8000 Merge branch 'stack_bug_fixes' of https://github.com/ellbee/immutable… · powercoder23/immutable-js@2da00fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 2da00fe

Browse files
committed
Merge branch 'stack_bug_fixes' of https://github.com/ellbee/immutable-js into ellbee-stack_bug_fixes
2 parents b061991 + 4357cc5 commit 2da00fe

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

__tests__/Stack.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe('Stack', () => {
6464
it('get helpers make for easier to read code', () => {
6565
var s = Stack.of('a', 'b', 'c');
6666
expect(s.first()).toBe('a');
67+
expect(s.last()).toBe('c');
6768
expect(s.peek()).toBe('a');
6869
});
6970

@@ -83,7 +84,14 @@ describe('Stack', () => {
8384
[1,'b'],
8485
[2,'c'],
8586
]);
86-
87+
88+
// map will cause reverse iterate
89+
expect(s.map(val => val + val).toArray()).toEqual([
90+
'aa',
91+
'bb',
92+
'cc',
93+
]);
94+
8795
var iteratorResults = [];
8896
var iterator = s.entries();
8997
var step;
@@ -95,6 +103,17 @@ describe('Stack', () => {
95103
[1,'b'],
96104
[2,'c'],
97105
]);
106+
107+
iteratorResults = [];
108+
iterator = s.toSeq().reverse().entries();
109+
while (!(step = iterator.next()).done) {
110+
iteratorResults.push(step.value);
111+
}
112+
expect(iteratorResults).toEqual([
113+
[0,'c'],
114+
[1,'b'],
115+
[2,'a'],
116+
]);
98117
});
99118

100119
it('push inserts at lowest index', () => {

dist/immutable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,6 +3278,7 @@
32783278

32793279
Stack.prototype.get = function(index, notSetValue) {
32803280
var head = this._head;
3281+
index = wrapIndex(this, index);
32813282
while (head && index--) {
32823283
head = head.next;
32833284
}
@@ -3410,7 +3411,7 @@
34103411

34113412
Stack.prototype.__iterate = function(fn, reverse) {
34123413
if (reverse) {
3413-
return this.toSeq().cacheResult.__iterate(fn, reverse);
3414+
return this.reverse().__iterate(fn);
34143415
}
34153416
var iterations = 0;
34163417
var node = this._head;
@@ -3425,7 +3426,7 @@
34253426

34263427
Stack.prototype.__iterator = function(type, reverse) {
34273428
if (reverse) {
3428-
return this.toSeq().cacheResult().__iterator(type, reverse);
3429+
return this.reverse().__iterator(type);
34293430
}
34303431
var iterations = 0;
34313432
var node = this._head;

0 commit comments

Comments
 (0)
0