Skip to content

Commit f7b56a7

Browse files
committed
fix cursor.cursor() using argument.length
When calling cursor.cursor(), the subCursor fn calls makeCursor and its logic expects arguments.length less than 4 to trigger making subCursor. Unfortunately subCursor calls it with 4 arguments, so we can correct this so that it will call with 3 or 4 depending on how it was called. This is an alternate fix to @jcranendonk's since the other fix checked if value was void 0 (undefined), however it might be valid to pass undefined to these functions, so the argument.length check is probably safer.
1 parent 3c66921 commit f7b56a7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

contrib/cursor/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ IndexedCursor.prototype = IndexedCursorPrototype;
220220
var NOT_SET = {}; // Sentinel value
221221

222222
function makeCursor(rootData, keyPath, onChange, value) {
223-
if (value === void 0) {
223+
if (arguments.length < 4) {
224224
value = rootData.getIn(keyPath);
225225
}
226226
var size = value && value.size;
@@ -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)