normalizr

how to denormalize entities from redux store?

点点圈 提交于 2021-01-28 19:08:16
问题 i have a data state in redux store like: { 123: { a: 'abc' }, 456: { a: 'def' }, 789: { a: 'ghi' }, } this is an array of objects like: const trainersArray= [ { _id: 123, a: 'abc' }, { _id: 456, a: 'def' }, { _id: 789, a: 'ghi' }, ] export const trainer = new schema.Entity( 'trainers', {}, { idAttribute: '_id' } ); const { trainers: normalizedTrainers } = normalize(trainersArray, [ trainer, ]).entities; now i want to denormalize like below in a component but i just don't get it? const

Redux normalizr - how can i merge all normalized object together

ぃ、小莉子 提交于 2021-01-28 06:00:12
问题 I am using redux with normlizr after normalizing the object I got the following store structure: { posts: { byId : { "123":{..obj}, "124":{..obj} } }, comments: { byId : { "123":{..obj}, "124":{..obj} } }, users:{ byId : { "123":{..obj}, "124":{..obj} } } } the ids are the same as the posts (post is the parent lets say) so when I select all posts I got smth like : { posts : [ { "id" : "123", ...data "comment":"123", "user": "123" } ] } but I would like the data of comment and user also inside

Is connect() in leaf-like components a sign of anti-pattern in react+redux?

旧巷老猫 提交于 2020-12-08 08:03:35
问题 Currently working on a react + redux project. I'm also using normalizr to handle the data structure and reselect to gather the right data for the app components. All seems to be working well. I find myself in a situation where a leaf-like component needs data from the store, and thus I need to connect() the component to implement it. As a simplified example, imagine the app is a book editing system with multiple users gathering feedback. Book Chapters Chapter Comments Comments Comments At

Is connect() in leaf-like components a sign of anti-pattern in react+redux?

半世苍凉 提交于 2020-12-08 08:03:04
问题 Currently working on a react + redux project. I'm also using normalizr to handle the data structure and reselect to gather the right data for the app components. All seems to be working well. I find myself in a situation where a leaf-like component needs data from the store, and thus I need to connect() the component to implement it. As a simplified example, imagine the app is a book editing system with multiple users gathering feedback. Book Chapters Chapter Comments Comments Comments At

Is connect() in leaf-like components a sign of anti-pattern in react+redux?

為{幸葍}努か 提交于 2020-12-08 08:02:27
问题 Currently working on a react + redux project. I'm also using normalizr to handle the data structure and reselect to gather the right data for the app components. All seems to be working well. I find myself in a situation where a leaf-like component needs data from the store, and thus I need to connect() the component to implement it. As a simplified example, imagine the app is a book editing system with multiple users gathering feedback. Book Chapters Chapter Comments Comments Comments At

Normalizr - is it a way to generate IDs for non-ids entity model?

断了今生、忘了曾经 提交于 2020-01-25 10:19:06
问题 I'm using normalizr util to process API response based on non-ids model. As I know, typically normalizr works with ids model, but maybe there is a some way to generate ids "on the go"? My API response example: ``` // input data: const inputData = { doctors: [ { name: Jon, post: chief }, { name: Marta, post: nurse }, //.... } // expected output data: const outputData = { entities: { nameCards : { uniqueID_0: { id: uniqueID_0, name: Jon, post: uniqueID_3 }, uniqueID_1: { id: uniqueID_1, name:

Structuring the store of a localized react / redux app

泄露秘密 提交于 2020-01-23 11:26:55
问题 I am having a hard time structure my data in a localized blogging app. My app is displaying posts, with embedded pictures (one-to-many), in three languages (English, French and Russian). The visitor can choose its locale. The editors can edit the localized versions of their posts in the three languages. For the moment, the structure of my store looks like this: { articles: { en: { 1: { id: 1, title: "my first title", body: "my first body", picture_ids: [1, 2, 3]}, 2: { id: 2, title: "my

ngrx normalized state selector

你。 提交于 2020-01-06 04:56:06
问题 I'm rewriting a Ionic project to work with ngrx because it is growing a lot and I need to maintain a centralized state. I have implemented it with ngrx and using normalized states with the help of Normalizr. Now I have a doubt on how to pass to dumb component a populated object: Suppose I have two interfaces: interface Conversation { date: Date, lastMessage: string //this is the id of a message entity coming from normalizr } and interface Message { content: string } Now when I'm trying to get

Unable to denormalize entity with the new Normalizr 3.1.0

梦想与她 提交于 2019-12-24 10:56:57
问题 I'm trying to denormalize a user back into a complete object. I'm trying to follow based on the docs here. From what I understand the input should be one of the result values, and then you provide the schema and entities to process rebuilding the object. The returned value though is an object that has a key of 0 and a value of the input. {0:44} for example, instead of the whole denormalized user object. userSchemas.js import { schema } from 'normalizr'; const photos = new schema.Entity(

What's the best way to deal with a normalized response?

梦想的初衷 提交于 2019-12-24 07:34:53
问题 I'm using normalizr to normalize a response. My problem is that I don't know how to manage the normalized response. { result:[] entities: { words: { //... 1: { definitions: [1, 2, 3] } // other word objects... }, definitions: { 1: 'blah blah' 2: 'blah blah' 3: 'blah blah' // definition objects } } } I want to pass the words to a react component with definitions. How can I retrieve the words with nested definitions and render it to my component. 回答1: webpackbin DEMO assuming that your state