【发布时间】:2020-01-09 07:09:58
【问题描述】:
是否可以采用嵌套的 JSON api 响应并使用 NgRx 实体库对其进行规范化? 如果我有一个看起来像这样的对象:
[
{
"id": "1",
"title": "My first post!",
"author": {
"id": "123",
"name": "Paul"
},
"comments": [
{
"id": "249",
"content": "Nice post!",
"commenter": {
"id": "245",
"name": "Jane"
}
},
{
"id": "250",
"content": "Thanks!",
"commenter": {
"id": "123",
"name": "Paul"
}
}
]
},
{
"id": "2",
"title": "This other post",
"author": {
"id": "123",
"name": "Paul"
},
"comments": [
{
"id": "251",
"content": "Your other post was nicer",
"commenter": {
"id": "245",
"name": "Jane"
}
},
{
"id": "252",
"content": "I am a spammer!",
"commenter": {
"id": "246",
"name": "Spambot5000"
}
}
]
}
]
我想用 NgRx Entity 让它尽可能平坦,这可能吗?如果可以,怎么做?
我尝试过使用 normalizr 库,它可以很好地展平对象,但它不适合 NgRx 辅助函数,例如 createReducers() 和 createActions()。
有人知道吗?
【问题讨论】:
标签: angular typescript redux rxjs ngrx