normalizr

编程之家收集整理的这个编程导航主要介绍了normalizr编程之家,现在分享给大家,也给大家做个参考。

normalizr

normalizr 介绍

normalizr可以将嵌套的jsON格式扁平化,方便被Redux利用;  

normalizr主要将获取的数据进一步格式化,在store创建一个虚拟数据库,数据通过id引用。

normalizr安装

yarn add normalizr

npm install normalizr

normalizr使用

没有normaliz 的情况:

{

"id": "123",

"author": {

"id": "1",

"name": "Paul"

},

"title": "My awesome blog post",

"comments": [

{

"id": "324",

"commenter": {

"id": "2",

"name": "Nicole"

}

}

]

}

引入normalizr代码:

import { normalize,schema } from 'normalizr';

// 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 normalizedData = normalize(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

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

johnny-five,Bocoup 的 JavaScript 机器和物联网编程框架
WePY,一款让小程序支持组件化开发的框架
Deep playground,神经网络的交互式可视化,使用d3.js和TypeS...
ShareDB,用于并发编辑系统的前端数据库
RxJS,RxJS 是使用 Observables 的响应式编程的库
egg-react-ssr,最小而美的Egg + React + SSR 服务端渲染应用...