Redux + Immutable jsの新機能です。toJSメソッドのパフォーマンス上の問題があります。しかし、私の使用例では、選択肢が見つかりませんでした。リストをオブジェクトの配列に変換する方法Reduxで.toJS()を使用せずに、不変のjsデータ構造をユースケース配列に変換する方法はありますか?
マイ初期状態
const initialState = fromJS({
postArr:[]
});
そして、私もそう私のwindow.Stateは不変のデータ構造にcovertedますSSRを使用しています
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
})
これは私のコンポーネントでありますベースのユースケース
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