normalizr

How do you add/remove to a redux store generated with normalizr?

耗尽温柔 提交于 2019-12-20 08:25:29
问题 Looking the examples from the README: Given the "bad" structure: [{ id: 1, title: 'Some Article', author: { id: 1, name: 'Dan' } }, { id: 2, title: 'Other Article', author: { id: 1, name: 'Dan' } }] It's extremely easy to add a new object. All I have to do is something like return { ...state, myNewObject } In the reducer. Now given the structure of the "good" tree, I have no idea how I should approach it. { result: [1, 2], entities: { articles: { 1: { id: 1, title: 'Some Article', author: 1 }

Why should I keep the state flat

删除回忆录丶 提交于 2019-12-09 09:06:54
问题 I'm using ReactJs with Redux and on some tutorials and codes I see people suggesting and using normalizr to keep the state flat . But what is the real advantage in keeping it flat ? Will I encounter any problems if I don't ? Is it necessary ? 回答1: Three main reasons: Updating nested Javascript objects immutably generally results in uglier code that is harder to maintain, unless you use a utility library to wrap up the process Immutably updating nested data requires that you return new copies

Structuring the store of a localized react / redux app

柔情痞子 提交于 2019-12-05 22:00:17
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 second title", body: "my second body", picture_ids: [1, 4, 5]}, 3: { id: 3, title: "my third title", body:

Normalizr - How to generate slug/id related to parent entity

元气小坏坏 提交于 2019-12-05 14:57:58
问题 How can I assign id/slug related to the entity's parent using normalizr? Example: API Response for a user call: { id: '12345', firstName: 'John', images: [ { url: 'https://www.domain.com/image0', name: 'image0' }, { url: 'https://www.domain.com/image1', name: 'image1' } ] } I could define my schemas in the following way: const image = new Schema('images'); const user = new Schema('users'); user.define({ images: arrayOf(image) }) The problem is that images don't have an id property, so

Why should I keep the state flat

北战南征 提交于 2019-12-03 10:53:39
I'm using ReactJs with Redux and on some tutorials and codes I see people suggesting and using normalizr to keep the state flat . But what is the real advantage in keeping it flat ? Will I encounter any problems if I don't ? Is it necessary ? Three main reasons: Updating nested Javascript objects immutably generally results in uglier code that is harder to maintain, unless you use a utility library to wrap up the process Immutably updating nested data requires that you return new copies of all items in the nesting hierarchy. Since components generally do shallow-equality reference comparisons

How do you add/remove to a redux store generated with normalizr?

风流意气都作罢 提交于 2019-12-02 14:10:27
Looking the examples from the README : Given the "bad" structure: [{ id: 1, title: 'Some Article', author: { id: 1, name: 'Dan' } }, { id: 2, title: 'Other Article', author: { id: 1, name: 'Dan' } }] It's extremely easy to add a new object. All I have to do is something like return { ...state, myNewObject } In the reducer. Now given the structure of the "good" tree, I have no idea how I should approach it. { result: [1, 2], entities: { articles: { 1: { id: 1, title: 'Some Article', author: 1 }, 2: { id: 2, title: 'Other Article', author: 1 } }, users: { 1: { id: 1, name: 'Dan' } } } } Every