Versent / redux-crud

A set of standard actions and reducers for Redux CRUD Applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storing instances in the Store

hwaterke opened this issue · comments

Hey,

I would like to store actual object instances in the store.
The problem is that redux-crud uses merge (from ramda) which creates new objects.

For example, when dispatching updateStart(new User())
I end-up with an object in the store instead of an instance of User.
This is because of the prepareRecord method which creates a new object rather than modifying the one being inserted.

I see. It was never the intention to support a use case like this. I don't know what the implication of doing something like this are with Redux. What about just storing the data?

Well, I started by storing the data as pure objects but storing instances has some very nice advantages.

The first one is to be able to use the following in your components:
user: React.PropTypes.instanceOf(User)
for data that comes directly from the store.

Then, when using TypeScript or FlowType, it is very nice to be able to type what is actually in the store.
You could argue that an interface would do the job just fine but I am using cerialize to convert JSON from HTTP calls to class instances automatically.
Storing the result in the store would be really nice.

Let me know what you think.

Hi after some consideration I have decided that we won't be doing this. I think that putting instances in the store goes recommended best practices in Redux. Which are to use immutable models that can be easily serialisable.

http://redux.js.org/docs/faq/OrganizingState.html#organizing-state-non-serializable

You an still use TypeScript or Flow we plain records.