Skip to content
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

feat(Entity): log a message when selectId returns undefined in dev mode #1169

Merged
merged 5 commits into from
Jul 16, 2018

Conversation

timdeschryver
Copy link
Member

Closes #1133

Example of the message:

image

@coveralls
Copy link

coveralls commented Jul 3, 2018

Coverage Status

Coverage increased (+0.04%) to 88.199% when pulling c7d7f43 on tdeschryver:pr/select-id-warning into e7de882 on ngrx:master.

});

it('should not warn when key does not exist in prod mode', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think it would be better to just set prod mode here and reset it after the selectIdValue function call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean with enableProdMode()? Because this threw an error because the platform was already set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Just didn't want to use the wildcard import if we didn't have to.

if (isDevMode() && key === undefined) {
console.warn(
'@ngrx/entity: The entity passed to the `selectId` implementation returned undefined. You should probably provide your own `selectId` implementation.',
'The entity that was passed:',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split up this sentence more.

const key = selectId(entity);

if (isDevMode() && key === undefined) {
console.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by that? You would also log this when the key would be null, false?

Copy link
Member

@brandonroberts brandonroberts Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We also want to warn if the selected id value is false, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thinking was to only check on undefined because the id property wouldn't exist on the entity, meaning you probably did something wrong. I'm not sure how this is implemented by other devs, because if one would define an entity as null, this is "hes choice" and he should know what he is doing.
Therefor I'm only checking on undefined.

For me it would also make more sense to check if the id value is false, but as I said I'm not sure how this is used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that makes sense. My rationale was that we're checking for values that aren't valid ids.

import { BookModel, AClockworkOrange } from './fixtures/book';

describe('Entity utils', () => {
describe(`selectIdValue()`, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need an additional test with a valid key that's undefined.

});

it('should not warn when key is undefined in dev mode', () => {
spyOn(ngCore, 'isDevMode').and.returnValue(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in prod mode

@brandonroberts brandonroberts merged commit 8f05f1f into ngrx:master Jul 16, 2018
@timdeschryver timdeschryver deleted the pr/select-id-warning branch July 16, 2018 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants