使用预平面阵列a.k.a. join来规范化不同的集合

时间:2016-11-14 07:15:47

标签: redux normalizr

所有normalizr示例都专注于嵌套对象,它们期望API结果如下所示:

{
  id: 1,
  title: 'Some Article',
  author: {
    id: 1,
    name: 'Dan'
  }
}

但实际上我发现你必须自己加入的以下格式是我最常处理的格式,我可以使用normalizr为我处理这个案例吗?

Posts [{ _id: 1, name: 'post text 1', userId: 5, locationId: 8}]

Locations [{ _id: 8, name: 'New York'}]

Users [{ _id: 5, name: 'John Doe', country: 'US'}]

预期结果:

{
  results: [1], // posts ids
  entities: {
    posts: {
      1: { name: 'post text 1', userId: 5, locationId: 8 }
    },
    users: {
      5: { name: 'John Doe', country: 'US' }
    },
    locations: {
      8: { name: 'New York' },
    }
  }
}

Docs / github问题就我找不到任何提及

0 个答案:

没有答案