深度克隆同时包含Immutable.js对象和普通JS对象的对象

问题描述

在我的应用程序中,我有一个同时包含Immutable.js对象和香草JS对象的对象。我想深深复制那个对象。使用Lodash的cloneDeep函数,我得到一条警告,内容为:iterable.length has been deprecated,use iterable.size or iterable.count().

有没有办法克隆整个对象?

我要深度克隆的对象如下:

obj: {
  immutableJSObj: EditorState,// this is the one that can't be copied with Lodash
  vanillaJSObj: {
    a: { c: ... },b: { d: ... }
  }
}

解决方法

我想我找到了解决方案。我知道Immutable.fromJS会深克隆一个Immutable.js对象。我能够对包含Immutable和VanillaJS对象的对象使用相同的功能。

示例:

const clonedObj = Immutable.fromJS(sentences).toJS()

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...