假设一个用户收藏了许多猫,当被问及用户的收藏时,api 端点给出了一个猫列表:
const catsList = [{id:1,name:"catA"},{id:2,name:"catB"},{id:3,name:"catC"}];
// ex: GET http://app.com/api/favorites => results in following json
{favorites:[{id:2,name:"catB"},{id:3,name:"catC"}]}
// the result is the list of cats
//and normalizr schema
const cats = new Schema('cats');
const favorites = new Schema('favorites');
现在我的问题是,我将如何规范化这些实体,以便得到以下结果,
entities.favorites=[2,3]; //2 and 3 are cats
entities.cats=[{id:1,name:"a"},{id:2,name:"b"},{id:3,name:"c"}];
我将如何使用 normalizr 完成此操作?