Skip to content

Deprecate getIn null throwing #1233

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
Sep 29, 2017
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
34 changes: 23 additions & 11 deletions __tests__/updateIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,29 @@ describe('updateIn', () => {
});

it('deep get throws if non-readable path', () => {
let deep = Map({ key: { regular: "jsobj" }, list: List([ Map({num: 10}) ]) });
expect(() =>
deep.getIn(["key", "foo", "item"]),
).toThrow(
'Invalid keyPath: Value at ["key"] does not have a .get() method: [object Object]',
);
expect(() =>
deep.getIn(["list", 0, "num", "badKey"]),
).toThrow(
'Invalid keyPath: Value at ["list",0,"num"] does not have a .get() method: 10',
);
let realWarn = console.warn;
let warnings: Array<any> = [];
console.warn = w => warnings.push(w);

try {
let deep = Map({ key: { regular: "jsobj" }, list: List([ Map({num: 10}) ]) });
deep.getIn(["key", "foo", "item"]);
expect(warnings.length).toBe(1);
expect(warnings[0]).toBe(
'Warning Invalid keyPath: Value at ["key"] does not have a .get() method: [object Object]' +
'\nThis functionality is deprecated and will throw in Immutable v5',
);

warnings.length = 0;
deep.getIn(["list", 0, "num", "badKey"]);
expect(warnings.length).toBe(1);
expect(warnings[0]).toBe(
'Warning Invalid keyPath: Value at ["list",0,"num"] does not have a .get() method: 10' +
'\nThis functionality is deprecated and will throw in Immutable v5',
);
} finally {
console.warn = realWarn;
}
});

it('deep has throws without list or array-like', () => {
Expand Down
18 changes: 12 additions & 6 deletions dist/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4666,12 +4666,18 @@ mixin(Collection, {
var i = 0;
while (i !== keyPath.length) {
if (!nested || !nested.get) {
throw new TypeError(
'Invalid keyPath: Value at [' +
keyPath.slice(0, i).map(quoteString) +
'] does not have a .get() method: ' +
nested
);
/* eslint-disable no-console */
typeof console === 'object' &&
console.warn &&
console.warn(
'Warning Invalid keyPath: Value at [' +
keyPath.slice(0, i).map(quoteString) +
'] does not have a .get() method: ' +
nested +
'\nThis functionality is deprecated and will throw in Immutable v5'
);
/* eslint-enable no-console */
return null;
}
nested = nested.get(keyPath[i++], NOT_SET);
if (nested === NOT_SET) {
Expand Down
Loading