redux-persist-immutable
redux-persist-immutable copied to clipboard
some state variable not reset properly when reused
Hello,
I might have found a bug. I have the following redux tree:
{
id: 'landcover_wood',
name: 'Landcover Wood',
active: false,
visible: true,
style: {
fill: 'rgba(237, 239, 245, 1)',
outline: 'rgba(181, 223, 245, 1)'
},
origstyle: {
fill: 'rgba(237, 239, 245, 1)',
outline: 'rgba(181, 223, 245, 1)'
}
},
{
id: 'water',
name: 'Water',
active: true,
visible: true,
style: {
fill: 'rgba(154, 172, 216, 1)'
},
origstyle: {
fill: 'rgba(225, 231, 245, 1)'
}
},
After persisting, the second node also has 'outline' sub elements, but with a value of zero:
{
id: 'water',
name: 'Water',
active: true,
visible: true,
style: {
fill: 'rgba(154, 172, 216, 1)',
outline: null
},
origstyle: {
fill: 'rgba(225, 231, 245, 1)',
outline: null
}
},
Can you help out?
Cheers Oliver
@oliverbienert that is odd, is outline: null
part of initial state?
No, it's not. Initial state is this:
state = Map({
hidemap: false,
layers: List()
}
Then I have an action called INIT_LAYERS
that fills the layers list with a list of Map objects. Data comes from a mapbox-gl-js instance wrapped in a react component. Some layers have a fill and an outline property (polygon layer such as landcover_wood in my example) some have just a fill colour (such as water or streets).
By the way, I also send this part of the redux tree to a REST API to store it in a database. For this to work I convert with toJS()
and back with fromJS()
, which works.
So I suspect the error somewhere in your code but I might be wrong.
we use https://github.com/glenjamin/transit-immutable-js to serialize the immutable objects. Perhaps the error lies in there?
I am not sure off the top of my head. Perhaps others will chime in with similar issues.
When I look at my state with the help of ReduxDevTools, the key in question seems to not exist, however when I debug my code, an immutable has("outline")
returns true
and in the dev tools I indeed see the key but with a value of undefined
.
So I'm afraid the error is in my code or I need a better understanding of how immutable works. Or it's the way redux works.
So for now, sorry for the noise.
All good. That sounds strange, and from the outside I have no idea what is going on. If you find resolution please post back here