我一直在尝试使用https://github.com/paularmstrong/normalizr为我的 redux 存储规范化嵌套数据
登录用户后,我会收到回复,其中包含他们的信息以及与其他数据类型的关系。
{
"data": {
"id": "207",
"type": "users",
"attributes": {
"email": "roberta@nitzsche.biz",
"last-sign-in-at": null,
"username": "april.johns",
"first-name": "Audie",
"last-name": "Halvorson",
"short-bio": "Ut exercitationem ",
"bio": "Ut exercitationem totam perferendis consequatur dolorem veritatis dolorem.",
"location": null,
"gender": "male",
"birthday": "1986-10-07",
"email-digest": "daily_digest",
"email-notifications": "instantl_notifications",
"auth-token": "_HV-S6qrdobecr-rr6gs",
"avatar-large-2x": "/missing_avatar.png",
"avatar-large": "/missing_avatar.png",
"cover-desktop-2x": "/missing_cover.png",
"cover-desktop": "/missing_cover.png",
"cover-mobile-2x": "/missing_cover.png",
"cover-mobile": "/missing_cover.png",
"wp-id": null,
"created-at": "2016-10-07T23:16:13.565Z",
"updated-at": "2016-10-07T23:16:13.565Z"
},
"relationships": {
"websites": {
"data": [
{
"id": 11,
"url": "http://mohr.org/coy_rowe",
"user-id": 207,
"created-at": "2016-10-07T23:16:13.651Z",
"updated-at": "2016-10-07T23:16:13.651Z"
}
]
},
"books": {
"data": [
{
"id": 11,
"name": "Outdoors & Industrial",
"image-url": "https://robohash.org/sitveritatisab.png?size=300x300&set=set1",
"author": "Meggie Balistreri",
"created-at": "2016-10-07T23:16:13.629Z",
"updated-at": "2016-10-07T23:16:13.629Z"
}
]
},
"movies": {
"data": [
{
"id": 11,
"name": "Movies, Home & Electronics",
"image-url": "https://robohash.org/quiaarchitectoodit.png?size=300x300&set=set1",
"author": "Eveline Ziemann",
"created-at": "2016-10-07T23:16:13.642Z",
"updated-at": "2016-10-07T23:16:13.642Z"
}
]
},
"interests": {
"data": [
{
"id": 22,
"name": "Synergistic Aluminum Gloves",
"created-at": "2016-10-07T23:16:13.596Z",
"updated-at": "2016-10-07T23:16:13.596Z"
}
]
},
"virtues": {
"data": [
{
"id": 22,
"name": "Ergonomic Wool Gloves",
"created-at": "2016-10-07T23:16:13.582Z",
"updated-at": "2016-10-07T23:16:13.582Z"
}
]
},
"features": {
"data": [
]
},
"strengths": {
"data": [
{
"id": 22,
"name": "Ergonomic Wool Gloves",
"created-at": "2016-10-07T23:16:13.582Z",
"updated-at": "2016-10-07T23:16:13.582Z"
}
]
},
"teachers": {
"data": [
{
"id": 22,
"name": "Ergonomic Wool Gloves",
"created-at": "2016-10-07T23:16:13.582Z",
"updated-at": "2016-10-07T23:16:13.582Z"
}
]
}
}
}
}
在阅读了很多教程之后,我相信我的标准化数据最好用这个形状来表示。
"currentUser" {
"lastUpdated": 0,
"userId": 207,
"attributes": {
"email": "roberta@nitzsche.biz",
"last-sign-in-at": null,
"username": "april.johns",
"first-name": "Audie",
"last-name": "Halvorson",
"short-bio": "Ut exercitationem ",
"bio": "Ut exercitationem totam perferendis consequatur",
// etc....
},
"relationships": {
"websites": [11],
"books": [22],
"movies": [33],
"interests": [21],
"virtues": [34],
"features": [22],
"strengths": [15],
"teachers": [45],
}
}
这是否意味着我为所有关系类型创建模式?
网站 书籍 电影 兴趣 美德 功能 优势 老师
然后是一个使用所有嵌套模式定义的关系模式?对于关系的所有类型,将在站点外的不同区域中引用。
例如)他们选择兴趣的页面,我会收到所有兴趣的回复。
[
{
"id": 54,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
{
"id": 55,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
{
"id": 56,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
{
"id": 57,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
}
]
我也将其标准化...
{
54: {
"id": 54,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
55: {
"id": 55,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
56: {
"id": 56,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
},
57: {
"id": 57,
"name": "Fantastic Wooden Hat",
"created_at": "2016-10-12T18:54:01.669Z",
"updated_at": "2016-10-12T18:54:01.669Z"
}
}
任何帮助将不胜感激,还有文章、教程、视频示例。
谢谢,