V
V
Viktor2019-09-17 00:20:58
JavaScript
Viktor, 2019-09-17 00:20:58

How does normalizr work?

{
  "id": "123",
  "author": {
    "id": "1",
    "name": "Paul"
  },
  "title": "My awesome blog post",
  "comments": [
    {
      "id": "324",
      "commenter": {
        "id": "2",
        "name": "Nicole"
      }
    }
  ]
}

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);

This is the Normalize utility. Tell me how the logic of this utility works. Read of. docks, but they are in English and I did not understand the logic. If possible, in simple words, how a normalized object is formed. What is user, why do we use it all the time

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Beetle, 2019-09-17
@Jukk

reduces the nesting of objects
https://habr.com/en/post/332628/
Such a structure is easy to read, easy to run a foreach loop through projects, render subcomponents with layer lists, and so on. But suppose we want to change the title of the page from id:1. Inside some small component that renders the page, $store.dispatch("changePageName",{id:1,name:"new name"}) is called. How to find the place where the required page with id: 1 lies in this deeply nested structure? Run through the entire vault? Not the best solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question