在新的Redux + Immutable js中,我发现了toJS方法的一些性能问题但是在我的用例中我找不到任何替代方法。所以如何将列表转换为对象数组。如何在不使用.toJS()的情况下将不可变的js数据结构隐藏到用例数组中?
我的初始化状态
const initialState = fromJS({
postArr:[]
});
而且我也使用SSR所以我window.State将coverted到不可变的数据结构
const initialState = window.__STATE__;
// Transform into Immutable.js collections,
// but leave top level keys untouched for Redux
Object
.keys(initialState)
.forEach(key => {
initialState[key] = fromJS(initialState[key]);
});
配置存储
import {combineReducers} from 'redux';
import {routerReducer} from 'react-router-redux';
import allPosts from './allPosts'
export default combineReducers({
allPosts,
//ForServerSide
routing: routerReducer
})
这是我的组件Based Use Case
const mapStateToProps = (state) => {
return{
posts:state.allPosts.get('postArr')
}
};
const mapDispatchToProps = (dispatch) => {
return {
getAllPosts:() => dispatch(allPosts.getAllPosts())
}
};
@connect(mapStateToProps,mapDispatchToProps)
但this.props.post仍然在寻找像不可改变的结构,但如何使用它对不起可怜的console.log陈述,但我想,以显示
List {size: 100, _origin: 0, _capacity: 100, _level: 5, _root: VNode…}
size
:
100
__altered
:
true
__hash
:
undefined
__ownerID
:
undefined
_capacity
:
100
_level
:
5
_origin
:
0
_root
:
VNode
_tail
:
VNode
__proto__
:
IndexedIterable