0
votes

I am new to react redux as well as use of the immutable.js library. I am wondering if it a bad idea or not to have my reducer return an instance of a Record as opposed to a simple object. The idea being that doing so would allow me to use convenient methods such as merge as opposed to having to write something like.

return Object.assign({}, state, updatedState)

Is there any compelling reason why one should NOT do this?

1

1 Answers

1
votes

It is not a bad idea to return record instance since Immutable.js will handle that for you. Your whole redux tree will be immutable therefore it will only be changed by its set of operations.

As mentioned here

Data encapsulated in an Immutable.JS object is never mutated. A new copy is always returned.

Workflow

Immutable.js makes data Persistant, therefore previous copies of the data is available and shares data via hash maps tries and vector tries.

Therefore there is no requirement to involve a costly operation such as cloning the data.

Need to copy the data from the cache is minimized which results it in being way more faster that the clone operation. It avoids creating new objects if there is no change in value.

Another thing to note is both Object.assign and spread operator are shallow operations. Hence, you need to do more modifications for nested operations.

You can check the performance of both here