This repository has been archived by the owner on Mar 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 869
Handle missing data in denormalize #232
Merged
paularmstrong
merged 1 commit into
paularmstrong:master
from
jeffcarbs:feature/handle-not-found
Feb 9, 2017
Merged
Handle missing data in denormalize #232
paularmstrong
merged 1 commit into
paularmstrong:master
from
jeffcarbs:feature/handle-not-found
Feb 9, 2017
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jeffcarbs
commented
Feb 9, 2017
@@ -63,7 +63,7 @@ export default class EntitySchema { | |||
|
|||
denormalize(entityOrId, unvisit, getDenormalizedEntity) { | |||
const entity = getDenormalizedEntity(this, entityOrId); | |||
if (typeof entity !== 'object') { | |||
if (typeof entity !== 'object' || entity === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discovered a fun fact about javascript while debugging this: typeof null === 'object'
Note there's a similar PR that was recently closed: #229. That PR returns null for the entire const foodSchema = new schema.Entity('foods');
const menuSchema = new schema.Entity('menus', {
food: foodSchema
});
const entities = {
menus: {
1: { id: 1, food: 2 }
},
foods: {
1: { id: 1 }
}
};
// On PR #229
denormalize(1, mySchema, entities) === null
denormalize(2, mySchema, entities) === null
// On this PR
denormalize(1, mySchema, entities) === {
"food": undefined,
"id": 1,
}
denormalize(2, mySchema, entities) === undefined |
4d43c07
to
88136e1
Compare
🎉 looks good to me! |
@jcarbo looks like you maybe don't check twitter anymore. Your changes have been published to v3.2.0 |
Thanks for the quick review/merge! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following from discussion here #228 (comment)
Problem
When an entity is not found during denormalization, it throws an unexpected exception.
Solution
During denormalization, if an entity is not found return undefined in its place.
NOTE: Initially I returned
null
where missing (null
orundefined
) data was. I've updated it to handle missing data by returning whatever was there, respecting eithernull
orundefined
.TODO