lumio
lumio

Reputation: 7575

Deep conversion of mutable data to immutable data with ImmutableJS

I keep my head cracking over the following problem. I load some data from a REST API which I then want to convert into a immutable state for redux.

My data looks something like this:

{
  name: 'Some string',
  components: [
    {
      type: 'SomeType',
      name: 'Another string,
      components: [
        {
          // and so on...
        }
      ]
    }
  ]
}

As you can tell, the data gets nested quite deeply and Immutables Map and List methods only convert the first level.

I was wondering how I could convert every Object and Array to an immutable state.

Upvotes: 0

Views: 275

Answers (1)

lumio
lumio

Reputation: 7575

Ok, turns out it is pretty forward.

I just need to use Immutable.fromJS.

Upvotes: 1

Related Questions