Skip to content

Commit 1984b2b

Browse files
committed
Minimal fix to immutable-js#97
1 parent 4c22e78 commit 1984b2b

File tree

4 files changed

+73
-18
lines changed

4 files changed

+73
-18
lines changed

__tests__/Cursor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,10 @@ describe('Cursor', () => {
172172
expect(onChange.mock.calls.length).toBe(1);
173173
});
174174

175+
it('maintains indexed sequences', () => {
176+
var data = Immutable.fromJS([]);
177+
var c = data.cursor();
178+
expect(c.toJS()).toEqual([]);
179+
});
180+
175181
});

dist/Immutable.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,14 +3424,36 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
34243424
}));
34253425
}
34263426
}, {}, Sequence);
3427-
Cursor.prototype[DELETE] = Cursor.prototype.remove;
3428-
Cursor.prototype.getIn = Cursor.prototype.get;
3427+
var CursorPrototype = Cursor.prototype;
3428+
CursorPrototype[DELETE] = CursorPrototype.remove;
3429+
CursorPrototype.getIn = CursorPrototype.get;
3430+
var IndexedCursor = function IndexedCursor(rootData, keyPath, onChange, length) {
3431+
this.length = length;
3432+
this._rootData = rootData;
3433+
this._keyPath = keyPath;
3434+
this._onChange = onChange;
3435+
};
3436+
($traceurRuntime.createClass)(IndexedCursor, {}, {}, IndexedSequence);
3437+
var IndexedCursorPrototype = IndexedCursor.prototype;
3438+
IndexedCursorPrototype.equals = CursorPrototype.equals;
3439+
IndexedCursorPrototype.deref = CursorPrototype.deref;
3440+
IndexedCursorPrototype.get = CursorPrototype.get;
3441+
IndexedCursorPrototype.getIn = CursorPrototype.getIn;
3442+
IndexedCursorPrototype.set = CursorPrototype.set;
3443+
IndexedCursorPrototype[DELETE] = IndexedCursorPrototype.remove = CursorPrototype.remove;
3444+
IndexedCursorPrototype.clear = CursorPrototype.clear;
3445+
IndexedCursorPrototype.update = CursorPrototype.update;
3446+
IndexedCursorPrototype.withMutations = CursorPrototype.withMutations;
3447+
IndexedCursorPrototype.cursor = CursorPrototype.cursor;
3448+
IndexedCursorPrototype.__iterate = CursorPrototype.__iterate;
3449+
IndexedCursorPrototype.__iterator = CursorPrototype.__iterator;
34293450
function makeCursor(rootData, keyPath, onChange, value) {
34303451
if (arguments.length < 4) {
34313452
value = rootData.getIn(keyPath);
34323453
}
34333454
var length = value instanceof Sequence ? value.length : null;
3434-
return new Cursor(rootData, keyPath, onChange, length);
3455+
var CursorClass = value instanceof IndexedSequence ? IndexedCursor : Cursor;
3456+
return new CursorClass(rootData, keyPath, onChange, length);
34353457
}
34363458
function wrappedValue(cursor, key, value) {
34373459
return value instanceof Sequence ? subCursor(cursor, key, value) : value;

0 commit comments

Comments
 (0)