使用 ImmutableJS 将可变数据深度转换为不可变数据

Deep conversion of mutable data to immutable data with ImmutableJS

我一直在思考以下问题。我从 REST API 加载了一些数据,然后我想将其转换为 redux 的不可变状态。

我的数据是这样的:

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

如您所知,数据嵌套很深,不可变的 Map 和 List 方法仅转换第一层。

我想知道如何将每个对象和数组转换为不可变状态。

好的,事实证明它很前卫。

我只需要使用Immutable.fromJS