gpbl / denormalizr

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

Fixed denormalization of nested non plain objects #9

Closed cecigarcia closed 8 years ago

cecigarcia commented 8 years ago

Added support to denormalize deeply nested objects, for example:

    const articleSchema = new Schema("article");
    const userSchema = new Schema("user");

    articleSchema.define({
      likes: {
        usersWhoLikes: arrayOf( userSchema )
      }
    });

data:

{
articles: [{
        id: 1,
        title: "Article 1",
        likes: {
          usersWhoLikes: [
          {
            id: 1,
            name: "John"
          },
          {
            id: 2,
            name: "Alex"
          }
          ]
        }
      }]
}

The current implementation denormalizes only first level attributes. Due to this, the denormalize function returns { articles: [ { id: 1, title: 'Article 1', likes: { usersWhoLikes: [ 1, 2 ] } } ] } (likes attribute is denormalized as a non entity object). Applying this fix, denormalize function returns the original data.

gpbl commented 8 years ago

Awesome, thanks!