normalizr下载
18603 2020-02-23 JavaScript MIT 官方网站
normalizr一款JSON数据规格化插件,normalizr很重要的一个作用就是把复杂的对象分开,变的更加清晰。不是所有的场景都适合用normalizr。
18603 2020-02-23 JavaScript MIT 官方网站
normalizr一款JSON数据规格化插件,normalizr很重要的一个作用就是把复杂的对象分开,变的更加清晰。不是所有的场景都适合用normalizr。
v3.2.3.zip(v3.2.4) 下载
v3.2.1.zip(v3.2.4) 下载
v3.2.2.zip(v3.2.4) 下载
v3.2.4.zip(v3.2.4) 下载
v3.4.0.zip(v3.4.0) 下载
v3.4.1.zip(v3.4.1) 下载
v3.3.0.zip(v3.3.0) 下载
v3.5.0.zip(v3.5.0) 下载
v3.2.0.zip(v3.2.0) 下载
v3.1.0.zip(v3.1.0) 下载
v3.6.0.zip(v3.6.0) 下载
Install from the NPM repository using yarn or npm:
yarn add normalizr
npm install normalizr
Many APIs, public or not, return JSON data that has deeply nested objects. Using data in this kind of structure is often very difficult for JavaScript applications, especially those using Flux or Redux.
Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.
Consider a typical blog post. The API response for a single post might look something like this:
{
"id": "123",
"author": {
"id": "1",
"name": "Paul"
},
"title": "My awesome blog post",
"comments": [
{
"id": "324",
"commenter": {
"id": "2",
"name": "Nicole"
}
}
]
}
We have two nested entity types within our article
: users
and comments
. Using various schema
, we can normalize all three entity types down:
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);
Now, normalizedData
will be:
{
result: "123",
entities: {
"articles": {
"123": {
id: "123",
author: "1",
title: "My awesome blog post www.itxst.com",
comments: [ "324" ]
}
},
"users": {
"1": { "id": "1", "name": "Paul" },
"2": { "id": "2", "name": "Nicole" }
},
"comments": {
"324": { id: "324", "commenter": "2" }
}
}
}
None.
Normalizr was originally created by Dan Abramov and inspired by a conversation with Jing Chen. Since v3, it was completely rewritten and maintained by Paul Armstrong. It has also received much help, enthusiasm, and contributions from community members.