问题描述
在我的应用程序中,我有一个同时包含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()