diegohaz / arc

React starter kit based on Atomic Design
https://arc.js.org
2.92k stars 292 forks source link

[redux] Entities, Post, and Resource #173

Closed ajhool closed 7 years ago

ajhool commented 7 years ago

Hi Diego, superb work and architecture!

I'm currently examining the relationship between Entities, Posts, and Resources in the fullstack branch. As far as I can tell, Entities is a middleware object for interfacing between Posts and Normalizr for parsing convenience. Thus, if I want to mimic a Posts object (eg. ImagePost), I could define the ImagePost schema in Entities and then use the Normalizr pattern. Is this a correct understanding? If so, what is the benefit of using this Entities pattern?

The Resource object does not seem to be used in the project at all, is Resource simply an example implementation of CRUD for a generic object?

diegohaz commented 7 years ago

Thank you for the words, @ajhool

We are currently writing new docs (https://github.com/diegohaz/arc/wiki) to better explain that stuff (feel free to help us). But, for now, you can refer to this repo: https://github.com/diegohaz/redux-modules

In short, the entities store is a redux module which you can plug in your app to get normalized state from other modules (e.g. post, resource). The benefit is that you have that feature encapsulated in just one place. It's easier to add, remove or upgrade normalizr.

The benefits of normalizr you can see on their repo, but, in short, with that you have "one single source of truth" for your entities. If some part of your code updates the data (user name), it will automatically be updated everywhere (on header bar, posts, profile etc.), since entity data exists in just one place.

And, yes, the resource module is simply an example.