futurice/pepperoni-app-kit

Rehydrated arrays

HZSamir opened this issue · 0 comments

Hello,
I've seen some issues about this, but no definitive answer, hence I'm posting.
I have added a new component called home which state is like this:

const initialState = Map({
  data: null,
  status: 'loading'
});

while my container looks like this:

// connect ...
data: state.getIn(['home', 'data']),

at component mount, an action GET_DATA is dispatched to fetch some remote data in the form of an array and insert it, data which will then be displayed in my view component, something like this:

render() {
// Some code
const {data} = this.props; 
content = data.map((item) => {
        <SomeItem prop={item.prop} />
});
//etc
}

At first launch, an array is correctly inserted into my state, and the getIn method does its job, returning an array. However, when restoring the state from the app storage, this time I get an immutable object full of mumbo-jumbo that I can't make sense of. Why is that? Why do I not simply get my immutable state and why is getIn not doing its job of returning a simple JS object?

This is kinda ruining the entire app, because in my case, data is fetched at app startup, regardless of whether is exists in the restored state (to keep it up-to-date), so when comparing a simple array against an immutable object (even when the data has not changed) Redux permutates them, believing them to be different.

Is there some way to remedy this?
Thank you.

PS: Sorry for the long issue. I thought I had to be as explicit as possible.