nor malizr 介绍
nor malizr可以将嵌套的jsON格式扁平化,方便被R edux 利用;
nor malizr主要将 获取 的数据进一步格式化,在store创建 一个 虚拟 数据库 ,数据通过id引用。
nor malizr安装
yarn add nor malizr
npm install nor malizr
nor malizr使用
没有 nor maliz 的情况:
{
"id": "123",
"author": {
"id": "1",
"name": "Paul"
},
"title": "My awesome blog post",
"comments": [
{
"id": "324",
"commenter": {
"id": "2",
"name": "Nicole"
}
}
]
}
引入 nor malizr 代码 :
import { nor malize,schema } from ' nor malizr';
// Define a users schema
const user = new schema.Entity('users');
// Define your comments schema
const comment = new schema.Entity('comments',{
commenter: user
});
// Define your article
const article = new schema.Entity('articles',{
author: user,
comments: [comment]
});
const nor malizedData = nor malize(originalData,article);
结果如下:
{
result: "123",
entities: {
"articles": {
"123": {
id: "123",
author: "1",
title: "My awesome blog post",
comments: [ "324" ]
}
},
"users": {
"1": { "id": "1","name": "Paul" },
"2": { "id": "2","name": "Nicole" }
},
"comments": {
"324": { id: "324","commenter": "2" }
}
}
}
网站地址 : https://github.com/paularmstrong/normalizr
GitHub: https://github.com/paularmstrong/normalizr
网站描述: 一款JSON数据范式化的js库
normalizr官方网站
官方网站: https://github.com/paularmstrong/normalizr
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。