在新的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