Normalizing simple array with normalizr

Viewed 5338

I'm just getting started with using normalizr with Redux and I'm stuck on what seems to me like a simple problem but I could be doing this wrong. So I want to normalize an array like this:

{
  articles: [
    {id: 1, someValue: 'test'},
    {id: 2, someValue: 'test2'}
  ]
}

into a structure like this:

{
  result: {
    articles: [1,2]
  },
  entities: {
    articles: {
      1: {someValue: 'test'},
      2: {someValue: 'test2'}
    }
  }
}

I have tried doing this:

const article = new Schema('articles');
responce = normalize(responce, {
  articles: arrayOf(article)
});

But that gives me a structure that looks like this:

{
  articles: {
    entities: {},
    result: {
      0: {someValue: 'test'},
      1: {someValue: 'test2'}
    }
  }
}

which now has no array of article ids. I am assuming I am missing something here:

article.define({
  ...
});

but can't figure what needs to go there in this simple case

1 Answers
Related