From 0986651df9398187390f4638424adb532985439f Mon Sep 17 00:00:00 2001 From: Jeroen Cranendonk Date: Tue, 27 Jan 2015 13:40:10 -0700 Subject: [PATCH] Fixed value check on makeCursor Certain code paths call makeCursor with four arguments, with 'value' undefined. Since arguments.length is still four in this case, the value is not retrieved from rootData, and an incorrect cursor type can be generated. --- contrib/cursor/__tests__/Cursor.ts | 7 +++++++ contrib/cursor/index.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/contrib/cursor/__tests__/Cursor.ts b/contrib/cursor/__tests__/Cursor.ts index 91adc3521c..e05c1e1460 100644 --- a/contrib/cursor/__tests__/Cursor.ts +++ b/contrib/cursor/__tests__/Cursor.ts @@ -49,6 +49,13 @@ describe('Cursor', () => { expect(deepCursor.deref()).toBe(data.getIn(Immutable.fromJS(['a', 'b']))); }); + it('cursor return new cursors of correct type', () => { + var data = Immutable.fromJS({ a: [1, 2, 3] }); + var cursor = Cursor.from(data); + var deepCursor = cursor.cursor('a'); + expect(deepCursor.findIndex).toBeDefined(); + }); + it('can be treated as a value', () => { var data = Immutable.fromJS(json); var cursor = Cursor.from(data, ['a', 'b']); diff --git a/contrib/cursor/index.js b/contrib/cursor/index.js index 206c310781..aa73e3a0ce 100644 --- a/contrib/cursor/index.js +++ b/contrib/cursor/index.js @@ -220,7 +220,7 @@ IndexedCursor.prototype = IndexedCursorPrototype; var NOT_SET = {}; // Sentinel value function makeCursor(rootData, keyPath, onChange, value) { - if (arguments.length < 4) { + if (value === void 0) { value = rootData.getIn(keyPath); } var size = value && value.size;