-
Notifications
You must be signed in to change notification settings - Fork 870
added a fallback strategy for denormalization #422
Conversation
#421 |
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.
I like that this has a very low added complexity. Though I feel like it needs really strong documentation with example code of when and why you would use it. Can you please add to the docs?
… passing entity when the fallback is only executed when entity is undefined, + updated tests and documentation
I have updated the relevant documentation, I hope it will suffice :) |
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.
Thanks!
Hi guys, Is there a way to skip missing references while denormalizing to avoid having for example here, in a use case I have, I want denormalizer to return const { schema, denormalize } = require('normalizr');
const a = {
id: 1,
b: 1,
c: [1, 2, 3]
}
const cSchema = new schema.Entity('c');
const aSchema = new schema.Entity('a', { c: [cSchema] });
const result = denormalize([1], [aSchema], { a: { 1: a }, c: {} }) available to run here https://runkit.com/mecp/5eb5baa8aad698001bb12788 |
Problem
In some cases I would like to denormalize a structure with a list of Ids instead of a list of subobjects (reasons could be to limit fetched data). When i normalize this structure the normalization works, I am left with the entity ids, but there is no way to create stubs for the entities itself, which I find ok since there could be an instance of the same object somewhere else in the structure.
But when denormalizing this I will get back an array with undefined items.
Solution
A possible solution to this could be to add a possibility to add a fallbackStrategy option to the EntitySchema where we could write our own fallback method for denormalization.
TODO