8000 Fix cursor to list failing to iterate, #283 · powercoder23/immutable-js@3a01864 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a01864

Browse files
committed
Fix cursor to list failing to iterate, immutable-js#283
1 parent 922fb69 commit 3a01864

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

contrib/cursor/__tests__/Cursor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ describe('Cursor', () => {
194194
);
195195
});
196196

197+
it('returns wrapped values for iteration API', () => {
198+
var jsData = [{val: 0}, {val: 1}, {val: 2}];
199+
var data = Immutable.fromJS(jsData);
200+
var cursor = Cursor.from(data);
201+
cursor.forEach(function (c, i) {
202+
expect(typeof c.deref).toBe('function'); // is a cursor!
203+
expect(c.get('val')).toBe(i);
204+
});
205+
});
206+
197207
it('can map over values to get subcursors', () => {
198208
var data = Immutable.fromJS({a: {v: 1}, b: {v: 2}, c: {v: 3}});
199209
var cursor = Cursor.from(data);

contrib/cursor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function updateCursor(cursor, changeFn, changeKey) {
254254
undefined,
255255
newRootData,
256256
cursor._rootData,
257-
newKeyPath(keyPath, changeKey)
257+
arguments.length > 2 ? newKeyPath(keyPath, changeKey) : keyPath
258258
);
259259
if (result !== undefined) {
260260
newRootData = result;
@@ -263,7 +263,7 @@ function updateCursor(cursor, changeFn, changeKey) {
263263
}
264264

265265
function newKeyPath(head, tail) {
266-
return tail ? Seq(head).concat(tail).toArray() : head;
266+
return Seq(head).concat(tail).toArray();
267267
}
268268

269269
exports.from = cursorFrom;

0 commit comments

Comments
 (0)
0