Je suis nouveau chez Redux + Immutable js J'ai trouvé un problème de performance avec la méthode toJS Mais dans mon cas d'utilisation, je n'ai trouvé aucune alternative. Alors, comment convertir une liste en tableau d'objets.Comment convertir une structure de données js Immuable en un tableau de cas d'utilisation sans utiliser .toJS() dans Redux?
Mon initialState
const initialState = fromJS({
postArr:[]
});
Je suis également en utilisant RSS donc mon window.State va coverted à la structure de données Immuable
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]);
});
Configurer magasin
import {combineReducers} from 'redux';
import {routerReducer} from 'react-router-redux';
import allPosts from './allPosts'
export default combineReducers({
allPosts,
//ForServerSide
routing: routerReducer
})
Ceci est mon composant Cas d'utilisation basé
const mapStateToProps = (state) => {
return{
posts:state.allPosts.get('postArr')
}
};
const mapDispatchToProps = (dispatch) => {
return {
getAllPosts:() => dispatch(allPosts.getAllPosts())
}
};
@connect(mapStateToProps,mapDispatchToProps)
Mais this.props.post encore Ressemblant Immuable Structure Mais comment l'utiliser désolé pour mauvaise présentation CONSOLE.LOG Mais je veux montrer
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