8000 MapCursor · designtestcode/immutable-js@d3d4158 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3d4158

Browse files
committed
MapCursor
1 parent 3752356 commit d3d4158

File tree

4 files changed

+50
-19
lines changed

4 files changed

+50
-19
lines changed

__tests__/Cursor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ describe('Cursor', () => {
3333
expect(missCursor.deref()).toBe(undefined);
3434
});
3535

36+
it('appears to be the type it points to', () => {
37+
var data = Immutable.fromJS(json);
38+
var cursor = data.cursor();
39+
expect(cursor instanceof Immutable.Map).toBe(true);
40+
});
41+
3642
it('gets return new cursors', () => {
3743
var data = Immutable.fromJS(json);
3844
var cursor = data.cursor();

dist/Immutable.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,13 +2065,13 @@ function spliceOut(array, idx, canEdit) {
20652065
var MAX_BITMAP_SIZE = SIZE / 2;
20662066
var MIN_ARRAY_SIZE = SIZE / 4;
20672067
var EMPTY_MAP;
2068-
var Cursor = function Cursor(rootData, keyPath, onChange, length) {
2068+
var MapCursor = function MapCursor(rootData, keyPath, onChange, length) {
20692069
this.length = length;
20702070
this._rootData = rootData;
20712071
this._keyPath = keyPath;
20722072
this._onChange = onChange;
20732073
};
2074-
($traceurRuntime.createClass)(Cursor, {
2074+
($traceurRuntime.createClass)(MapCursor, {
20752075
equals: function(second) {
20762076
return is(this.deref(), second && (typeof second.deref === 'function' ? second.deref() : second));
20772077
},
@@ -2157,6 +2157,10 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
21572157
return m.asImmutable();
21582158
}));
21592159
},
2160+
wasAltered: function() {
2161+
var deref = this.deref();
2162+
return !!(deref && deref.__altered);
2163+
},
21602164
__iterate: function(fn, reverse) {
21612165
var $__0 = this;
21622166
var deref = this.deref();
@@ -2181,16 +2185,20 @@ var Cursor = function Cursor(rootData, keyPath, onChange, length) {
21812185
var v = entry[1];
21822186
return iteratorValue(type, k, wrappedValue($__0, k, v), step);
21832187
}));
2188+
},
2189+
__ensureOwner: function(ownerID) {
2190+
return updateCursor(this, (function(m) {
2191+
return m.__ensureOwner(ownerID);
2192+
}));
21842193
}
2185-
}, {}, Sequence);
2186-
Cursor.prototype[DELETE] = Cursor.prototype.remove;
2187-
Cursor.prototype.update = MapPrototype.update;
2194+
}, {}, Map);
2195+
MapCursor.prototype[DELETE] = MapCursor.prototype.remove;
21882196
function makeCursor(rootData, keyPath, onChange, value) {
21892197
if (arguments.length < 4) {
21902198
value = rootData.getIn(keyPath);
21912199
}
21922200
var length = value instanceof Sequence ? value.length : null;
2193-
return new Cursor(rootData, keyPath, onChange, length);
2201+
return new MapCursor(rootData, keyPath, onChange, length);
21942202
}
21952203
function wrappedValue(cursor, key, value) {
21962204
return value instanceof Sequence ? subCursor(cursor, key, value) : value;
@@ -2208,6 +2216,9 @@ function updateCursor(cursor, changeFn, changeKey) {
22082216
}
22092217
var updateIn = applyUpdateIn(keyPath, changeFn);
22102218
var newRootData = typeof rootData.deref === 'function' ? updateCursor(rootData, updateIn, editPath) : updateIn(rootData);
2219+
if (newRootData === rootData) {
2220+
return rootData;
2221+
}
22112222
onChange && onChange(newRootData, rootData, editPath);
22122223
return makeCursor(newRootData, keyPath, onChange);
22132224
}

0 commit comments

Comments
 (0)
0