gpbl / denormalizr

Denormalize data normalized with normalizr
https://www.npmjs.com/package/denormalizr
MIT License
228 stars 24 forks source link

Denormalize arrays, ids, and arrays of ids #13

Closed jeffcarbs closed 8 years ago

jeffcarbs commented 8 years ago

Fixes #3

This PR updates the denormalize function to handle denormalizing lists when the schema is an IterableSchema (i.e. arrayOf(someEntitySchema)). I did some refactoring as part of that work, and a nice side effect was being able to denormalize just by passing the id (or array of ids). This was already how denormalizing nested arrays was handled, so I think it makes sense to expose at the top level.

A cool side effect is the greater symmetry with normalizr. This is now true:

const { result, entities } = normalize(response, schema);
denormalize(result, entities, schema) == response
jeffcarbs commented 8 years ago

Just squashed the commits and amended the last one. Initially the updates here allowed the normalized entities (during non-immutable usage) to be mutated. However, I realized this probably isn't ideal especially for people using this with redux since denormalized entities would wind up back in the store.

I added some specs failing specs to confirm and updated the functionality so they pass. It will now safely denormalize without mutating the passed entities.

If all goes well and this winds up getting merged, could you publish a new version to NPM? Thanks!

jeffcarbs commented 8 years ago

@gpbl - do you think you'll have a chance to review this over the weekend? I'm currently hard-coding this in a project of mine and would love avoid that 😄

igorbarbashin commented 8 years ago

I'm voting for this feature! Thanks @jcarbo for implementing

gpbl commented 8 years ago

Published as 0.3.0 (with the immutable-js support as well). Thanks @jcarbo again 👍 please forgive me for the delay on merging it 🙏 I hope it didn't cause too much problems with your project!