Skip to content

Commit 577c9a0

Browse files
committed
Merge pull request immutable-js#381 from jeffbski/subCursor-fix
subCursor (cursor.cursor('a')) returns improper type
2 parents 625e2ce + f7b56a7 commit 577c9a0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

contrib/cursor/__tests__/Cursor.ts

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ describe('Cursor', () => {
4949
expect(deepCursor.deref()).toBe(data.getIn(Immutable.fromJS(['a', 'b'])));
5050
});
5151

52+
it('cursor return new cursors of correct type', () => {
53+
var data = Immutable.fromJS({ a: [1, 2, 3] });
54+
var cursor = Cursor.from(data);
55+
var deepCursor = <any>cursor.cursor('a');
56+
expect(deepCursor.findIndex).toBeDefined();
57+
});
58+
5259
it('can be treated as a value', () => {
5360
var data = Immutable.fromJS(json);
5461
var cursor = Cursor.from(data, ['a', 'b']);

contrib/cursor/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ function wrappedValue(cursor, keyPath, value) {
233233
}
234234

235235
function subCursor(cursor, keyPath, value) {
236+
if (arguments.length < 3) {
237+
return makeCursor( // call without value
238+
cursor._rootData,
239+
newKeyPath(cursor._keyPath, keyPath),
240+
cursor._onChange
241+
);
242+
}
236243
return makeCursor(
237244
cursor._rootData,
238245
newKeyPath(cursor._keyPath, keyPath),

0 commit comments

Comments
 (0)