Skip to content

subCursor (cursor.cursor('a')) returns improper type #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions contrib/cursor/__tests__/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <any>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']);
Expand Down
7 changes: 7 additions & 0 deletions contrib/cursor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ function wrappedValue(cursor, keyPath, value) {
}

function subCursor(cursor, keyPath, value) {
if (arguments.length < 3) {
return makeCursor( // call without value
cursor._rootData,
newKeyPath(cursor._keyPath, keyPath),
cursor._onChange
);
}
return makeCursor(
cursor._rootData,
newKeyPath(cursor._keyPath, keyPath),
Expand Down