Should every object in the store state be immutable?

210 views Asked by At

I am learning React.js and Flux, and I understand that is better to keep the object immutable because comparing them is O(1).

My situation is this: I have a store, which has a _state object, that is a map (I'm using Immutable-js). That _state has some booleans, some strings and an array. The array has objects, all of them are immutable maps.

The question is, should I use an immutable list instead of an array? What is the benefit? I'm not going to compare the array against another array.

Thanks for reading!

1

There are 1 answers

0
Marc Johnston On BEST ANSWER

It depends on the design of the object. If you are adding elements to the list and handling the new immutable collections that are returned, then you need the immutable list. Otherwise, use the lighter-weight arrays.

So it is more of a matter of: are you needing the immutable list; if not, use an array for lighter weight.